Skip to content

Commit 69150ec

Browse files
committed
---
yaml --- r: 284383 b: refs/heads/swift-5.1-branch c: 5c42961 h: refs/heads/master i: 284381: 90a7b0a 284379: fd4d9c6 284375: 67ca6eb 284367: 8b9df93 284351: 0773ae6
1 parent 61b02e3 commit 69150ec

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
12441244
refs/heads/swift-5.1-old-llvm-branch: 9cef8175146f25b72806154b8a0f4a3f52e3e400
1245-
refs/heads/swift-5.1-branch: 4a28dfc13bba4a5910820d4070f4d6e8b7605444
1245+
refs/heads/swift-5.1-branch: 5c42961c9c366503b7108eb066f54b43677c4b98
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e
12481248
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-03-a: 4591c933063ddcb0d6cd6d0cdd01086b2f9b244d

branches/swift-5.1-branch/include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,9 @@ WARNING(function_type_usable_from_inline_warn,none,
15191519
ERROR(opaque_type_invalid_constraint,none,
15201520
"an 'opaque' type must specify only 'Any', 'AnyObject', protocols, "
15211521
"and/or a base class", ())
1522+
ERROR(inferred_opaque_type,none,
1523+
"property definition has inferred type %0, involving the '__opaque' "
1524+
"return type of another declaration", (Type))
15221525

15231526
// Extensions
15241527
ERROR(non_nominal_extension,none,

branches/swift-5.1-branch/lib/Sema/TypeCheckDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,15 @@ static void validatePatternBindingEntry(TypeChecker &tc,
987987
if (!pattern->hasType() || pattern->getType()->hasUnboundGenericType()) {
988988
if (tc.typeCheckPatternBinding(binding, entryNumber))
989989
return;
990+
991+
// A pattern binding at top level is not allowed to pick up another decl's
992+
// opaque result type as its type by type inference.
993+
if (!binding->getDeclContext()->isLocalContext()
994+
&& binding->getInit(entryNumber)->getType()->hasOpaqueArchetype()) {
995+
// TODO: Check whether the type is the pattern binding's own opaque type.
996+
tc.diagnose(binding, diag::inferred_opaque_type,
997+
binding->getInit(entryNumber)->getType());
998+
}
990999
}
9911000

9921001
// If the pattern binding appears in a type or library file context, then

branches/swift-5.1-branch/test/type/opaque.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ func zlop() -> __opaque C & AnyObject & P {
5656
return D()
5757
}
5858

59+
// Don't allow opaque types to propagate by inference into other global decls'
60+
// types
61+
struct Test {
62+
let inferredOpaque = bar() // expected-error{{inferred type}}
63+
let inferredOpaqueStructural = Optional(bar()) // expected-error{{inferred type}}
64+
let inferredOpaqueStructural2 = (bar(), bas()) // expected-error{{inferred type}}
65+
}
66+
5967
//let zingle = {() -> __opaque P in 1 } // FIXME ex/pected-error{{'opaque' types are only implemented}}
6068

6169
// Invalid positions

0 commit comments

Comments
 (0)