Skip to content

Commit

Permalink
Fix rdar://23681566, a bug noticed by Marcin Krzyzanowski on twitter …
Browse files Browse the repository at this point in the history
…where

we would reject an invalid @objc enum with:

<unknown>:0: error: cannot assign value of type '(progress: Int) -> Status' to type 'Status'

because we were poking at the enum element before it was validated.
  • Loading branch information
lattner committed Nov 29, 2015
1 parent 714dcd5 commit 4b898ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,9 @@ static void checkEnumRawValues(TypeChecker &TC, EnumDecl *ED) {
llvm::SmallDenseMap<RawValueKey, RawValueSource, 8> uniqueRawValues;

for (auto elt : ED->getAllElements()) {
// Make sure the element is checked out before we poke at it.
TC.validateDecl(elt);

if (elt->isInvalid())
continue;

Expand Down
6 changes: 6 additions & 0 deletions test/Parse/objc_enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ class Bar {
@objc func foo(x: Foo) {}
@objc func nonObjC(x: NonObjCEnum) {} //expected-error{{type of the parameter cannot be represented in Objective-C}} //expected-note{{non-'@objc' enums cannot be represented in Objective-C}}
}

// <rdar://problem/23681566> @objc enums with payloads rejected with no source location info
@objc enum r23681566 : Int { // expected-note {{declared raw type 'Int' here}}
case Foo(progress: Int) // expected-error {{enum with raw type cannot have cases with arguments}}
}

4 changes: 4 additions & 0 deletions test/Parse/pointer_conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func f23202128() {
let pipe: [Int32] = [0, 0] // expected-note {{change 'let' to 'var' to make it mutable}}}}
UMP(&pipe) // expected-error {{cannot pass immutable value as inout argument: 'pipe' is a 'let' constant}}

var pipe2: [Int] = [0, 0]
UMP(&pipe2) // expected-error {{cannot convert value of type '[Int]' to expected argument type 'Int32'}}


UP(pipe) // ok
UP(&pipe) // expected-error {{'&' is not allowed passing array value as 'UnsafePointer<Int32>' argument}} {{6-7=}}
}
Expand Down

0 comments on commit 4b898ce

Please sign in to comment.