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

Fail Macro Expansion if JavaStaticField is used in non-class #174

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

jrosen081
Copy link
Contributor

Closes #65

This adds support for failing macro expansion if JavaStaticField is used in the incorrect context.

One thing I was thinking is we can add similar logic for the JavaStaticMethod to fail in that context. That will fail in compilation, but it could be nicer to fail expansion vs fail in an implementation detail (of a function not existing on the type)

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, minor comment

@ktoso
Copy link
Collaborator

ktoso commented Nov 10, 2024

Tests failed, something isn't quite right:


/__w/swift-java/swift-java/Sources/JavaKit/generated/JavaBoolean.swift:31:3: error: Cannot use @JavaStaticField outside of a JavaClass instance (from macro 'JavaStaticField')
29 | }
30 | extension JavaClass<JavaBoolean> {
31 |   @JavaStaticField(isFinal: true)
   |   `- error: Cannot use @JavaStaticField outside of a JavaClass instance (from macro 'JavaStaticField')
32 |   public var TRUE: JavaBoolean!
33 | 

@jrosen081
Copy link
Contributor Author

Tests failed, something isn't quite right:




/__w/swift-java/swift-java/Sources/JavaKit/generated/JavaBoolean.swift:31:3: error: Cannot use @JavaStaticField outside of a JavaClass instance (from macro 'JavaStaticField')

29 | }

30 | extension JavaClass<JavaBoolean> {

31 |   @JavaStaticField(isFinal: true)

   |   `- error: Cannot use @JavaStaticField outside of a JavaClass instance (from macro 'JavaStaticField')

32 |   public var TRUE: JavaBoolean!

33 | 

Oh my. I'm checking for classdecl, but I think I need to check for extensiondecl. I'll fix this up soon

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you very much!

@ktoso ktoso merged commit 867128b into swiftlang:main Nov 15, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JavaKit's @JavaStaticField could detect that it should not be used on static field
2 participants