Skip to content

Commit 80372ed

Browse files
authored
Merge pull request #26082 from jckarter/opaque-stored-property-interface-types
Followup fixes for stored opaque-type properties.
2 parents dafd027 + 6b2b4a0 commit 80372ed

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Type GenericEnvironment::mapTypeIntoContext(GenericEnvironment *env,
124124
Type MapTypeOutOfContext::operator()(SubstitutableType *type) const {
125125
auto archetype = cast<ArchetypeType>(type);
126126
if (isa<OpaqueTypeArchetypeType>(archetype->getRoot()))
127-
return type;
127+
return Type();
128128

129129
return archetype->getInterfaceType();
130130
}

lib/AST/Type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,8 +3278,9 @@ static Type substType(Type derivedType,
32783278
return None;
32793279

32803280
// If we have a substitution for this type, use it.
3281-
if (auto known = substitutions(substOrig))
3281+
if (auto known = substitutions(substOrig)) {
32823282
return known;
3283+
}
32833284

32843285
// If we failed to substitute a generic type parameter, give up.
32853286
if (isa<GenericTypeParamType>(substOrig)) {

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ static bool validateTypedPattern(TypeChecker &TC,
697697
auto opaqueTy = TC.getOrCreateOpaqueResultType(resolution,
698698
named->getDecl(),
699699
opaqueRepr);
700-
TL.setType(opaqueTy);
700+
TL.setType(named->getDecl()->getDeclContext()
701+
->mapTypeIntoContext(opaqueTy));
701702
hadError = opaqueTy->hasError();
702703
} else {
703704
TC.diagnose(TP->getLoc(), diag::opaque_type_unsupported_pattern);

test/type/opaque.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,24 @@ func foo<T: P_52528543>(x: T) -> some P_52528543 {
437437
.frob(a_b: x.a.b)
438438
.frob(a_b: x.a.b) // expected-error {{cannot convert}}
439439
}
440+
441+
struct GenericFoo<T: P_52528543, U: P_52528543> {
442+
let x: some P_52528543 = T()
443+
let y: some P_52528543 = U()
444+
445+
mutating func bump() {
446+
var xab = f_52528543(x: x)
447+
xab = f_52528543(x: y) // expected-error{{cannot assign}}
448+
}
449+
}
450+
451+
func f_52528543<T: P_52528543>(x: T) -> T.A.B { return x.a.b }
452+
453+
func opaque_52528543<T: P_52528543>(x: T) -> some P_52528543 { return x }
454+
455+
func invoke_52528543<T: P_52528543, U: P_52528543>(x: T, y: U) {
456+
let x2 = opaque_52528543(x: x)
457+
let y2 = opaque_52528543(x: y)
458+
var xab = f_52528543(x: x2)
459+
xab = f_52528543(x: y2) // expected-error{{cannot assign}}
460+
}

0 commit comments

Comments
 (0)