Skip to content

Commit e99961e

Browse files
committed
AST: Fix Substitution::subst to substitute associated types from conformance witnesses instead of by name.
Fixes a crash when property behavior uses are run through the specializer, since they set up associated type conformances that are not recoverable by name lookup.
1 parent c0b432d commit e99961e

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

lib/AST/Substitution.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ getSubstitutionMaps(GenericParamList *context,
4343
// Save the conformances from the substitution so that we can substitute
4444
// them into substitutions that map between archetypes.
4545
conformanceMap[arch] = sub.getConformances();
46-
47-
if (arch->isPrimary())
48-
typeMap[arch] = sub.getReplacement();
46+
typeMap[arch] = sub.getReplacement();
4947
}
5048
assert(subs.empty() && "did not use all substitutions?!");
5149
}

test/Interpreter/property_behavior.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
// RUN: %target-run %t/a.out
55
// REQUIRES: executable_test
66

7-
// TODO: Fix specializer to substitute using conformance type witnesses instead
8-
// of name lookup
9-
10-
// XFAIL: swift_test_mode_optimize
11-
// XFAIL: swift_test_mode_optimize_unchecked
12-
137
import StdlibUnittest
148

159
protocol delayedImmutable {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -emit-sil -parse-as-library -O -enable-experimental-property-behaviors %s | FileCheck %s
2+
3+
@inline(never) func whatever<T>() -> T { fatalError("") }
4+
5+
protocol lazzy {
6+
associatedtype Value
7+
}
8+
extension lazzy {
9+
var value: Value {
10+
return whatever()
11+
}
12+
}
13+
14+
struct Foo {
15+
var [lazzy] x: Int
16+
17+
init() {}
18+
}
19+
20+
public func exercise() {
21+
_ = Foo().x
22+
}
23+
24+
// CHECK-LABEL: sil @_TF28specialize_property_behavior8exerciseFT_T_
25+
// CHECK: function_ref @_TTSg5Si___TF28specialize_property_behavior8whateverurFT_x

0 commit comments

Comments
 (0)