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

Generated code fails to compile with option -Ymacro-annotations #254

Closed
ngbinh opened this issue Feb 22, 2021 · 9 comments
Closed

Generated code fails to compile with option -Ymacro-annotations #254

ngbinh opened this issue Feb 22, 2021 · 9 comments

Comments

@ngbinh
Copy link

ngbinh commented Feb 22, 2021

Minimal reproduce: https://github.com/ngbinh/scalablyTypedDemo

Command to run ./sbt "stImport; compile"

With -Ymacro-annotations:

[info] compiling 298 Scala sources to /home/binh/works/external/scalablyTypedDemo/target/scala-2.13/classes ...                                                                                                                                               
[error] /home/binh/works/external/scalablyTypedDemo/src/main/scala/scalablytyped/anduin.facades/monacoEditor/mod/KeyCode.scala:19:17: ABNT_C1 is already defined as (compiler-generated) case class companion object ABNT_C1                                  
[error]   /* 110 */ val ABNT_C1: anduin.facades.monacoEditor.mod.KeyCode.ABNT_C1 with Double = js.native                                                                                                                                                      
[error]                 ^                                                                                                                                                                                                                                     
[error] /home/binh/works/external/scalablyTypedDemo/src/main/scala/scalablytyped/anduin.facades/monacoEditor/mod/KeyCode.scala:23:17: ABNT_C2 is already defined as (compiler-generated) case class companion object ABNT_C2                                  
[error]   /* 111 */ val ABNT_C2: anduin.facades.monacoEditor.mod.KeyCode.ABNT_C2 with Double = js.native                                                                                                                                                      
[error]                 ^                                                                                                                                                                                                                                     
[error]           

without -Ymacro-annotations:

[info] compiling 298 Scala sources to /home/binh/works/external/scalablyTypedDemo/target/scala-2.13/classes ...
[info] 2410 unused info messages; change -Wconf for cat=unused to display individual messages
[info] 1678 w-flag info messages; change -Wconf for cat=w-flag to display individual messages
[success] Total time: 17 s, completed Feb 22, 2021, 6:32:35 PM
@oyvindberg
Copy link
Collaborator

Thank you!

Ok, so I actually removed this on purpose in https://github.com/ScalablyTyped/Converter/pull/206/files#diff-da6c28724a5d5545c5420f648170b6187962e05c09a9b02492d807ae44aed60f . Sufficient amount of time passed between me making that change and me writing the (already rather long) release note, so I completely forgot to put it in.

I took out that transformation with a workaround out at the time because:

  • I needed to either drop it, or spend time finding a new fix and re-implementing it on top of the new encoding described in the beta30 release notes.
  • It seemed better to invest time in Scala 3 support than to work around very old bugs in scalac.
  • It only affects people using the source-gen plugin and macro annotations, which I expect are very few.

Anyways, I'll see whether it's easy to patch up a fix for, otherwise here are a two workarounds:

Manual fix-up

Just a few errors? you can manually delete them or rewrite them to object. Something like this:

- val a: A = js.native
+ object A extends org.scalablytyped.TopLevel[A]

The source generator with checked in sources is a very flexible solution because it's easy to do small manual fixes like this.

Split your build

Otherwise, split your project in two, where you compile the generated code without macro annotations, and add another sbt project which depends on the first where you enable macro annotations

@oyvindberg
Copy link
Collaborator

I should probably add that normal usage of ST ensures that the scala macro compiler flag is not set, because the plugin instantiates its own compiler. Only with the source-gen is this a possible scenario

@ngbinh
Copy link
Author

ngbinh commented Feb 22, 2021

Thanks, splitting builds should work.

@ngbinh
Copy link
Author

ngbinh commented Feb 23, 2021

@oyvindberg I updated https://github.com/ngbinh/scalablyTypedDemo to show another issue that seems to be a legitimate issue.

running ./sbt "stImport; compile results in:

info] compiling 172 Scala sources to /home/binh/works/external/scalablyTypedDemo/target/scala-2.13/classes ...                                                                                                                                               
[error] /home/binh/works/external/scalablyTypedDemo/src/main/scala/scalablytyped/anduin.facades/echarts/echarts/EChartOption.scala:3525:12: object Slider is defined twice;                                                                                   
[error]   the conflicting method Slider was defined at line 3521:9                                                                                                                                                                                            
[error]     object Slider {
[error]            ^
[error] /home/binh/works/external/scalablyTypedDemo/src/main/scala/scalablytyped/anduin.facades/echarts/echarts/EChartOption.scala:3241:12: object Inside is defined twice;
[error]   the conflicting method Inside was defined at line 3237:9
[error]     object Inside {
[error]            ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

Looks into the code:

    @scala.inline
    def Slider(): anduin.facades.echarts.echarts.EChartOption.DataZoom.Slider = {
      val __obj = js.Dynamic.literal()
      __obj.asInstanceOf[anduin.facades.echarts.echarts.EChartOption.DataZoom.Slider]
    }
    object Slider {
      
      @scala.inline
      def apply(): Slider = {
        val __obj = js.Dynamic.literal()
        __obj.asInstanceOf[Slider]
      }
      

looks like def Slider() is conflicted with object Slider apply method.

I can obviously modify the code by hand and commit it in but not sure if this is the real issue as the code will not compile without macro annotation. It will not even compile with empty scalacOptions

@oyvindberg
Copy link
Collaborator

Thanks again @ngbinh !

I was vaguely aware that echarts had broken after running the CI build, ScalablyTyped/Distribution@9c9ccdc , but hadnt had time to investigate it. This will have to be fixed :)

@ngbinh
Copy link
Author

ngbinh commented Feb 23, 2021

Cool, thanks

@oyvindberg
Copy link
Collaborator

#255

@ngbinh
Copy link
Author

ngbinh commented Feb 24, 2021

great! I will try it out on the next release

@ngbinh
Copy link
Author

ngbinh commented Mar 25, 2021

trying beta-31 now. Can confirm that the work around (remove macro-annotations) works. So I will close this issue for now

@ngbinh ngbinh closed this as completed Mar 25, 2021
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

No branches or pull requests

2 participants