Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1072] Nested type named Type should be better dealt with #43684

Open
an0 mannequin opened this issue Mar 26, 2016 · 3 comments
Open

[SR-1072] Nested type named Type should be better dealt with #43684

an0 mannequin opened this issue Mar 26, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@an0
Copy link
Mannequin

an0 mannequin commented Mar 26, 2016

Previous ID SR-1072
Radar rdar://47994817
Original Reporter @an0
Type Bug
Environment

Swift 3 in Xcode 8.0 beta 3

Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6e55591eaee67c084dcc85c1bde947ff

is duplicated by:

  • SR-9897 '.Type' property on a type can't be escaped with backticks
  • SR-10278 Nested type named Type is not properly resolved
  • SR-13547 enum: Type member must not be named Type

relates to:

  • SR-2172 Compiler mistreats static Type property

Issue Description:

This code produces this error:

type 'Region.Type' has no member 'Unknown'

I know this is because `.Type` accesses meta type. So either the error message should be more clear or `Type` should be forbidden as name of nest types.

struct Region {
    enum Type {
        case Unknown
        case DarkOnLight
        case LightOnDark
    }
}

let v = Region.Type.Unknown
@belkadan
Copy link
Contributor

Swift 3 has a new error message for this:

<stdin>:2:10: error: type member may not be named 'Type', since it would conflict with the 'foo.Type' expression
    enum Type {
         ^
<stdin>:2:10: note: backticks can escape this name if it is important to use
    enum Type {
         ^~~~
         `Type`

@an0
Copy link
Mannequin Author

an0 mannequin commented Jul 8, 2016

Just verified that the error message is correct in Swift 3. However, the fix suggestion is bad:

If this name is unavoidable, use backticks to escape it.

After auto fix, enum Type changes to enum `Type` and the� name collision remains.

@swift-ci
Copy link
Collaborator

Comment by Lloyd Torres (JIRA)

We're seeing this issue on our Swift 3.0 project as well. Given an enum named `Type`, we cannot access its members or functions.

Here's a code snippet that reproduces the issue:

class Sample {
    public enum `Type`:Int {
        case foo = 1
        case bar = 2
    }
}

let val1 = Sample.Type.foo      // Type 'Sample.Type' has no member 'foo'
let val2 = Sample.`Type`.foo    // Type 'Sample.Type' has no member 'foo'

let rawValue = 1
let val3: Sample.Type? = Sample.Type(rawValue: rawValue)        // Argument passed to call that takes no arguments
let val4: Sample.`Type`? = Sample.`Type`(rawValue: rawValue)    // Argument passed to call that takes no arguments

Here's our environment:

  • swiftlang-800.0.46.2

  • clang-800.0.38

  • Xcode 8.0 (8A218a)

  • x86_64-apple-macosx10.9

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants