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-12069] Type checking fails for force unwrapped implicit member expression #54505

Closed
swift-ci opened this issue Jan 23, 2020 · 5 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12069
Radar rdar://problem/58997113
Original Reporter jumhyn (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee jumhyn (JIRA)
Priority Medium

md5: 3fee7e2012d0c78b84e0004df4851cdf

Issue Description:

The following code produces an error on the last line:

struct A { static var a: A? = A() }

func f(_ a: A?) {}
func g(_ a: A) {}

f(.a)
g(.a!) // Error: Type of expression is ambiguous without more context

IMO, this should succeed. In g(.a!) the type of .a should be inferred as A? just as it is on the line above (which compiles without error).

@theblixguy
Copy link
Collaborator

On master, I get this:

/Users/suyashsrijan/Desktop/test.swift:7:4: error: type 'A?' has no member 'a'
g(.a!)
  ~^

@swift-ci
Copy link
Collaborator Author

Comment by Frederick Kellison-Linn (JIRA)

Thanks @theblixguy! I figured the diagnostic had likely improved with the new diagnostics system but didn't have a toolchain around to test with. It looks like the type checker just isn't looking through the optional for the implicit member expression here.

@beccadax
Copy link
Contributor

@swift-ci create

@hborla
Copy link
Member

hborla commented Jul 16, 2021

This is fixed in 5.5. Funny enough, jumhyn (JIRA User) I suspect you may have fixed this yourself with the implementation of SE-0287!

@swift-ci
Copy link
Collaborator Author

Comment by Frederick Kellison-Linn (JIRA)

Ha! I think you're probably right about that—generalizing implicit member syntax cleaned up a lot of little inconsistencies like this, but I forgot that I had reported this. Looks like this was filed just a day after the pitch thread for SE-0287; I must have been exploring the existing limits of implicit member syntax.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants