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-10545] The rhs of as/as?/as!/is is not a type expression. #52945

Open
Dante-Broggi opened this issue Apr 24, 2019 · 1 comment
Open

[SR-10545] The rhs of as/as?/as!/is is not a type expression. #52945

Dante-Broggi opened this issue Apr 24, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation

Comments

@Dante-Broggi
Copy link
Contributor

Previous ID SR-10545
Radar rdar://problem/19938681
Original Reporter @Dante-Broggi
Type Bug
Environment

Xcode 10.2 default toolchain.

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

md5: 79c282ebc732fb0ff683f5330121a87a

Issue Description:

I would expect the following function to return `5` if called with `Int.self`, and `nil` otherwise.

It doesn't compile, because the rhs of `as?` is evaluated more like a declaration than the expression it is.

func foo<T>(_ ty: T.Type) -> T? {
  let x : Any = 5
  let y = x as? ty // error: Use of undeclared type 'ty'
  return y
}

I suppose this is on the border of being a language improvement, rather than a bug, due to the duration this has existed and the differences between declaration type references and expression type references, but I still believe this is a bug.

@belkadan
Copy link
Contributor

I think "the expression it is" is presumptuous; it has always been a type representation.

@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 feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

2 participants