Skip to content

Commit dc8650c

Browse files
committed
Adjust access level of inaccessible protocol members in diagnostics.
Otherwise we hit one of the "%error" cases in the diagnostic text, which results in an assert. Fixes rdar://problem/40111079.
1 parent e22bed2 commit dc8650c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -489,8 +489,9 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
489489
if (inaccessibleResults) {
490490
// FIXME: What if the unviable candidates have different levels of access?
491491
const ValueDecl *first = inaccessibleResults.front().getValueDecl();
492-
diagnose(Loc, diag::candidate_inaccessible,
493-
Name, first->getFormalAccess());
492+
diagnose(Loc, diag::candidate_inaccessible, Name,
493+
first->adjustAccessLevelForProtocolExtension(
494+
first->getFormalAccess()));
494495

495496
// FIXME: If any of the candidates (usually just one) are in the same
496497
// module we could offer a fix-it.

test/NameBinding/Inputs/has_accessibility.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ extension HasDefaultImplementation {
4040
internal func foo() {}
4141
}
4242
internal class InternalBase {}
43+
44+
open class ImplementsInternalProtocol {}
45+
46+
protocol InternalProtocol {}
47+
extension InternalProtocol {
48+
public var i: Int { return 1 }
49+
}
50+
51+
extension ImplementsInternalProtocol : InternalProtocol {}

test/NameBinding/accessibility.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,7 @@ public class TestablePublicSub: InternalBase {} // expected-error {{undeclared t
169169
// <unknown>:0: error: unexpected note produced: 'method()' declared here
170170
// <unknown>:0: error: unexpected note produced: 'method' declared here
171171
// <unknown>:0: error: unexpected note produced: 'method' declared here
172+
173+
class AccessMemberOfInternalProtocol : ImplementsInternalProtocol {
174+
func testProperty() { let _ = i } // expected-error {{'i' is inaccessible due to 'internal' protection level}}
175+
}

0 commit comments

Comments
 (0)