File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -3044,12 +3044,21 @@ ProtocolConformanceRef ReplaceOpaqueTypesWithUnderlyingTypes::
3044
3044
operator ()(CanType maybeOpaqueType, Type replacementType,
3045
3045
ProtocolDecl *protocol) const {
3046
3046
auto abstractRef = ProtocolConformanceRef (protocol);
3047
-
3047
+
3048
3048
auto archetypeAndRoot = getArchetypeAndRootOpaqueArchetype (maybeOpaqueType);
3049
3049
if (!archetypeAndRoot) {
3050
- assert (maybeOpaqueType->isTypeParameter () ||
3051
- maybeOpaqueType->is <ArchetypeType>());
3052
- return abstractRef;
3050
+ if (maybeOpaqueType->isTypeParameter () ||
3051
+ maybeOpaqueType->is <ArchetypeType>())
3052
+ return abstractRef;
3053
+
3054
+ // SIL type lowering may have already substituted away the opaque type, in
3055
+ // which case we'll end up "substituting" the same type.
3056
+ if (maybeOpaqueType->isEqual (replacementType)) {
3057
+ return inContext->getParentModule ()
3058
+ ->lookupConformance (replacementType, protocol);
3059
+ }
3060
+
3061
+ llvm_unreachable (" origType should have been an opaque type or type parameter" );
3053
3062
}
3054
3063
3055
3064
auto archetype = archetypeAndRoot->first ;
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-emit-silgen -disable-availability-checking -verify %s
2
+ protocol P { }
3
+ extension Int : P { }
4
+
5
+ func foo( ) -> some P { return 0 }
6
+ func bar< T: P > ( _ x: T ) -> some P { return x }
7
+
8
+ struct Bas < T: P > { init ( _: T ) { } }
9
+
10
+ func abstraction_level< T> ( x: T ) -> ( T ) -> ( ) {
11
+ return { _ in ( ) }
12
+ }
13
+
14
+ func test( ) {
15
+ abstraction_level ( x: Bas ( bar ( foo ( ) ) ) ) ( Bas ( bar ( foo ( ) ) ) )
16
+ }
You can’t perform that action at this time.
0 commit comments