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-6179] Strange error with typealiases and extensions #48731

Closed
swift-ci opened this issue Oct 18, 2017 · 4 comments
Closed

[SR-6179] Strange error with typealiases and extensions #48731

swift-ci opened this issue Oct 18, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6179
Radar rdar://problem/35104086
Original Reporter BenLeggiero (JIRA User)
Type Bug
Status Resolved
Resolution Cannot Reproduce
Environment
  • macOS Sierra 10.12.6 (16G29)

    • Xcode Version 8.3.3 (8E3004b)

      • Swift 3.0
    • Xcode Version 9.0.1 (9A1004)

      • Swift 3.2

      • Swift 4.0

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

md5: 50944bc48fdef42021aa45761bcee0ab

relates to:

  • SR-631 Extensions in different files do not recognize each other

Issue Description:

Observed behavior:

The following fails to compile in the same way for Swift 3.0, 3.2, and 4.0:

// MARK: Basis

public class Foo {
    public typealias Bar = [String : Int]
}


func take(fooBar: Foo.Bar) {
    print(fooBar)
}


// MARK: Problems

public typealias FooBar = Foo.Bar



extension Dictionary
    where Key == FooBar.Key,
        Value == FooBar.Value {
    
    func baz() {
        take(fooBar: self)
    }
}


// MARK: Usages

let fb = FooBar()
fb.baz()
take(fooBar: [:])

The above code emits the following errors:

main.swift:16:31: error: type alias 'Bar' is not a member type of 'Foo'
public typealias FooBar = Foo.Bar
                          ~~~ ^
main.swift:25:22: error: cannot convert value of type 'Dictionary<Key, Value>' to expected argument type 'Foo.Bar' (aka 'Dictionary<String, Int>')
        take(fooBar: self)
                     ^~~~
                          as! Foo.Bar

However, the following compiles and runs with no warnings or errors:

// MARK: Basis

public class Foo {
    public typealias Bar = [String : Int]
}


func take(fooBar: Foo.Bar) {
    print(fooBar)
}


// MARK: No Problems

public typealias FooBar = Foo.Bar



let fb = FooBar()



extension Dictionary
    where Key == FooBar.Key,
        Value == FooBar.Value {
    
    func baz() {
        take(fooBar: self)
    }
}


// MARK: Usages

fb.baz()
take(fooBar: [:])

Expected behavior:

Both compile and run identically.


Original discovery and discussion: https://stackoverflow.com/q/46816925/3939277

@belkadan
Copy link
Contributor

@swift-ci create

@slavapestov
Copy link
Member

Seems to work in 4.2.

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Oct 24, 2018

BenLeggiero (JIRA User), Could you please verify that the issue is resolved in Xcode 10 and if so move the state of the bug to closed?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 1, 2019

Comment by Ky (JIRA)

Tested and verified in Xcode 10.2.1 (10E1001) and 11.0 beta (11M336w). The described problem doesn't exist, and both snippets compile successfully and run identically.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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

3 participants