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-12082] Self does not work as a shortcut for type attributes #54518

Open
DevAndArtist mannequin opened this issue Jan 24, 2020 · 6 comments
Open

[SR-12082] Self does not work as a shortcut for type attributes #54518

DevAndArtist mannequin opened this issue Jan 24, 2020 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself parser Area → compiler: The legacy C++ parser type checker Area → compiler: Semantic analysis

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Jan 24, 2020

Previous ID SR-12082
Radar rdar://problem/58997176
Original Reporter @DevAndArtist
Type Bug
Environment

Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)

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

md5: 80cf95b31a78c28d50ccda13f4fe72c9

Issue Description:

@_functionBuilder
struct FunctionBuilder {}

extension FunctionBuilder {
  // error: Expected an attribute name
  static func build<T>(@Self content: () -> T) -> T {
    content()
  }
}
@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Jan 24, 2020

cc @johnno1962

@theblixguy
Copy link
Collaborator

Hmm, seems reasonable. cc @rintaro should we allow this as a special-case?

@beccadax
Copy link
Contributor

@swift-ci create

@rintaro
Copy link
Mannequin

rintaro mannequin commented Jan 26, 2020

Not sure how @Self should be handled for class es, but the Parser definitely should parse it as an attribute name.

@theblixguy
Copy link
Collaborator

I suppose for non-classes it would just be the type, but for classes it won’t be a valid name unless the class is final. WDYT?

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Jan 26, 2020

I‘m not sure this is fully correct though, at least if we take a look at a function builder example in context of a class.

What if you have a base function builder which is a class and provides some static builder functions and the `build` function from above. Then a subclass provides more static builder functions.

@_functionbuilder
class Base {
  static func build<T>(@Self content: () -> T) -> T { content() }
  static func buildEither(first: ...) -> ...
  static func buildEither(second: ...) -> ...
}
// still non final
class Sub: Base {
  static func buildIf(...) -> ...
}

let builder: Base.Type = Sub.self
// I think build should still be able to use all builder functions from Base
// up to Sub even though at this point this is transparent
builder.build { ... }

I think Self in such context should remain dynamic.

cc @slavapestov

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

No branches or pull requests

2 participants