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

Do not autoimport scala.* when parsing .java files #7312

Closed
ekrich opened this issue Sep 24, 2019 · 1 comment · Fixed by #9394
Closed

Do not autoimport scala.* when parsing .java files #7312

ekrich opened this issue Sep 24, 2019 · 1 comment · Fixed by #9394

Comments

@ekrich
Copy link
Contributor

ekrich commented Sep 24, 2019

overview

Calling Java methods that return a non-primitive Java object from Scala causes a runtime error. Examples:
java.lang.Long
java.lang.Boolean
...

minimized code

package beanconfig;

public class NumbersConfig {
    private long longVal;
    private Long longObj;

    public long getLongVal() { return longVal; }
    public void setLongVal(long longVal) { this.longVal = longVal; }
    public Long getLongObj() { return longObj; }
    public void setLongObj(Long longObj) { this.longObj = longObj; }
}

Calling code.

assertEquals(4L, beanConfig.getLongObj)

result

[error] Test org.ekrich.config.impl.ConfigBeanFactoryTest.testCreateNumber failed: java.lang.NoSuchMethodError: beanconfig.NumbersConfig.getLongObj()J, took 0.059 sec
[error]     at org.ekrich.config.impl.ConfigBeanFactoryTest.testCreateNumber(ConfigBeanFactoryTest.scala:115)

expectation

Code should run.

work around

Fully specify return value

 public java.lang.Long getLongObj() { return longObj; }
@TheElectronWill TheElectronWill self-assigned this Jul 17, 2020
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 21, 2020
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 21, 2020
Instead of setting the scala root imports in the rootContext,
set it later and choose the right import depending on the language (java and scala).
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 21, 2020
Instead of setting the scala root imports in the rootContext,
set them later and choose the right import depending on the language (java and scala).
TheElectronWill added a commit to TheElectronWill/dotty that referenced this issue Jul 21, 2020
Instead of setting the scala root imports in the rootContext,
set them later and choose the right imports depending on the language (java or scala).
odersky added a commit that referenced this issue Aug 10, 2020
Fix #7312: Choose root imports based on the source file
@ekrich
Copy link
Contributor Author

ekrich commented Aug 11, 2020

I can confirm that Java methods returning Long and Double now work on 0.27.0-bin-20200810-74ba21c-NIGHTLY.
Reference: ekrich/sconfig#55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants