Last active
May 31, 2017 14:58
-
-
Save yanli0303/2e844d734a3a993526df85af79143b46 to your computer and use it in GitHub Desktop.
Crash Swift compiler by defining a local variable with same name as class property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Foo { | |
var bar: Int? = 1 | |
} | |
enum BarEnum: Int { | |
case zero = 0 | |
case one = 1 | |
case two = 2 | |
} | |
extension Foo { | |
func confuseCompiler() { | |
// `bar` is a class property, defining a local variable `bar` crashes swift compiler | |
guard let barEnumRawValue = bar, let bar = BarEnum(rawValue: barEnumRawValue) else { | |
return | |
} | |
print(bar) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment