Skip to content

Commit 36c9da5

Browse files
committed
Sema: Don't build conformance requirements with class type in OpaqueResultTypeRequest
The GSB just let this slide, but the requirement machine asserts.
1 parent a356adc commit 36c9da5

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,20 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
226226
if (constraintType->hasError())
227227
return nullptr;
228228

229-
// Error out if the constraint type isn't a class or existential type.
230-
if (!constraintType->isConstraintType() &&
231-
!constraintType->getClassOrBoundGenericClass()) {
229+
RequirementKind kind;
230+
if (constraintType->isConstraintType())
231+
kind = RequirementKind::Conformance;
232+
else if (constraintType->getClassOrBoundGenericClass())
233+
kind = RequirementKind::Superclass;
234+
else {
235+
// Error out if the constraint type isn't a class or existential type.
232236
ctx.Diags.diagnose(currentRepr->getLoc(),
233237
diag::opaque_type_invalid_constraint);
234238
return nullptr;
235239
}
236240

237241
assert(!constraintType->hasArchetype());
238-
requirements.emplace_back(RequirementKind::Conformance, paramType,
239-
constraintType);
242+
requirements.emplace_back(kind, paramType, constraintType);
240243
}
241244

242245
interfaceSignature = buildGenericSignature(ctx, outerGenericSignature,

test/IRGen/dynamic_replaceable_opaque_return_type_parameter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -disable-availability-checking -enable-implicit-dynamic -enable-private-imports %S/Inputs/opaque_return_type_parameter.swift -module-name Repo -emit-module -emit-module-path %t/Repo.swiftmodule
3-
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -emit-ir | %FileCheck %s
4-
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -c -o %t/tmp.o
2+
// RUN: %target-swift-frontend -disable-availability-checking -enable-implicit-dynamic -enable-private-imports %S/Inputs/opaque_return_type_parameter.swift -module-name Repo -emit-module -emit-module-path %t/Repo.swiftmodule -requirement-machine-abstract-signatures=verify
3+
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -emit-ir -requirement-machine-abstract-signatures=verify | %FileCheck %s
4+
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -c -o %t/tmp.o -requirement-machine-abstract-signatures=verify
55
@_private(sourceFile: "opaque_return_type_parameter.swift") import Repo
66

77
// Make sure we are not emitting a replacement for the opaque result type used as parameter (Assoc).

test/SILGen/opaque_result_type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3-
// RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift -requirement-machine-abstract-signatures=verify
3+
// RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s -requirement-machine-abstract-signatures=verify | %FileCheck %s
44

55
import resilient_struct
66

test/type/opaque.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify -requirement-machine-abstract-signatures=verify %s
22

33
protocol P {
44
func paul()

test/type/opaque_generic_superclass_constraint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -verify %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -verify -requirement-machine-abstract-signatures=verify %s
22

33
// rdar://problem/53318811
44

0 commit comments

Comments
 (0)