-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make main methods invisible #11546
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
Make main methods invisible #11546
Conversation
Add a new flag Invisible that gets set for compiler-generated main methods. Invisible symbols are skipped when resolving members during typechecking. They become visible after typechecking. With that mechanism, we can accept main methods that are themselves called `main`.
Load bean properties in TreeUnpickler but make them invisible to Typer. This looks like the safer choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this approval is to acknowledge the changes to the Tasty version, I have not checked the rest
@smarter Do you want to take a look? |
val isScala2MacroDefinedInScala3 = flags.is(Macro, butNot = Inline) && flags.is(Erased) | ||
ctx.owner match { | ||
case cls: ClassSymbol if (!isScala2MacroDefinedInScala3 || cls == defn.StringContextClass) && !isSyntheticBeanAccessor => | ||
case cls: ClassSymbol if !isScala2MacroDefinedInScala3 || cls == defn.StringContextClass => | ||
// Enter all members of classes that are not Scala 2 macros or synthetic bean accessors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Enter all members of classes that are not Scala 2 macros or synthetic bean accessors. | |
// Enter all members of classes that are not Scala 2 macros |
@@ -670,6 +668,7 @@ class TreeUnpickler(reader: TastyReader, | |||
case PARAMalias => addFlag(SuperParamAlias) | |||
case EXPORTED => addFlag(Exported) | |||
case OPEN => addFlag(Open) | |||
case INVISIBLE => addFlag(Invisible) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag should be visible in tasty-reflect too /cc @nicolasstucki
final val SPLITCLAUSE = 45 | ||
final val INVISIBLE = 46 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLegalTag
in this file still says:
firstSimpleTreeTag <= tag && tag <= SPLITCLAUSE ||
presumably that should be replaced with INVISIBLE
(we should really add something like final val LAST_SIMPLE_TAG = INVISIBLE
to avoid having to update multiple places like this).
@@ -211,7 +211,8 @@ Standard-Section: "ASTs" TopLevelStat* | |||
PARAMsetter -- The setter part `x_=` of a var parameter `x` which itself is pickled as a PARAM | |||
PARAMalias -- Parameter is alias of a superclass parameter | |||
EXPORTED -- An export forwarder | |||
OPEN -- an open class | |||
OPEN | |||
INVISIBLE -- an open class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment on wrong line (and inconsistently indented).
Does it make the generated class invisible? Or also the annotated method? |
I’ve noticed that when using the REPL I can’t call methods annotated with package example
def foo(): Unit = println("foo")
@main def run(): Unit = println("run") Then, in the REPL,
Would this PR solve the issue? Or should I open a new issue? |
BTW, it also makes the completion crash:
|
I just tried it out and yes, with this PR the repl does call the method |
@nicolasstucki Can you check the last commit please? |
final val EMPTYCLAUSE = 44 | ||
final val SPLITCLAUSE = 45 | ||
final val INVISIBLE = 46 | ||
final val INVISIBLE = 44 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normally this would require a MajorVersion
bump, but as we have not yet had a stable ExperimentalVersion
this is fine
@nicolasstucki Could you have a quick review of the last commit, then we can merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the reflection interface look good
@smarter are all the requested changes Ok? Can we merge? |
I think this PR brought some regression. Having this branch
You can find more details in CI actions at this PR (rebased on the newest master) #11578 |
@BarkingBad This doesn't sound like a bug in this PR, it sounds like the scaladoc task is doing something wrong and trying to use tasty files generated by the reference compiler with the current compiler, but those are intentionally incompatible. |
Add a new flag
Invisible
that gets set for compiler-generated main methods.Invisible symbols are skipped when resolving members during typechecking.
They become visible after typechecking.
With that mechanism, we can accept main methods that are themselves called
main
.