Skip to content

Fix JavaMethodType creation and parameter matching of JavaMethodTypes #345

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

Merged
merged 1 commit into from
Feb 11, 2015

Conversation

olhotak
Copy link
Contributor

@olhotak olhotak commented Jan 31, 2015

Based on #339.

Fixes java-override test.

The Java method did have a JavaDefined flag.

The bugs were:

  • Namer ignored the JavaDefined flag and made a MethodType anyway, instead of a JavaMethodType.
  • TypeComparer.matchingParams had the isJava tests for the two methods switched.

@olhotak olhotak changed the title Fix javamethodtype Fix JavaMethodType creation and parameter matching of JavaMethodTypes Jan 31, 2015
@olhotak olhotak force-pushed the fix-javamethodtype branch from 17424b1 to 03a37a5 Compare January 31, 2015 20:38
@olhotak
Copy link
Contributor Author

olhotak commented Feb 1, 2015

Scalac converts Object to Any in both UnPickler (for .class inputs) and in Namers (for Java source inputs):

       val makeMethodType = (vparams: List[Symbol], restpe: Type) => {
          // TODODEPMET: check that we actually don't need to do anything here
          // new dependent method types: probably OK already, since 'enterValueParams' above
          // enters them in scope, and all have a lazy type. so they may depend on other params. but: need to
          // check that params only depend on ones in earlier sections, not the same. (done by checkDependencies,
          // so re-use / adapt that)
          if (meth.isJavaDefined)
          // TODODEPMET necessary?? new dependent types: replace symbols in restpe with the ones in vparams
            JavaMethodType(vparams map (p => p setInfo objToAny(p.tpe)), restpe)
          else
            MethodType(vparams, restpe)
        }

Dotty does it only in UnPickler, but (currently) not in Namer.

To be consistent with Scalac, we could additionally do it in Namer, and then revert the change that switched things in matchingParams.

Alternatively, we can think about whether in Dotty, we want Java Object to be represented internally as Any or Object. If we decide to keep it as Object, then we would need to remove the conversion from UnPickler for consistency.

@odersky
Copy link
Contributor

odersky commented Feb 1, 2015

Ah I see. I think dotty needs to behave like scalac here. The problem is
that Scala does not have a concept of auto-boxing as Java does. So we
cannot pass an Int to an Object. But people have come to expect that this
works if the Object is the type of a Java parameter.

On Sun, Feb 1, 2015 at 8:52 AM, Ondřej Lhoták [email protected]
wrote:

Scalac converts Object to Any in both UnPickler (for .class inputs) and in
Namers (for Java source inputs):

   val makeMethodType = (vparams: List[Symbol], restpe: Type) => {
      // TODODEPMET: check that we actually don't need to do anything here
      // new dependent method types: probably OK already, since 'enterValueParams' above
      // enters them in scope, and all have a lazy type. so they may depend on other params. but: need to
      // check that params only depend on ones in earlier sections, not the same. (done by checkDependencies,
      // so re-use / adapt that)
      if (meth.isJavaDefined)
      // TODODEPMET necessary?? new dependent types: replace symbols in restpe with the ones in vparams
        JavaMethodType(vparams map (p => p setInfo objToAny(p.tpe)), restpe)
      else
        MethodType(vparams, restpe)
    }

Dotty does it only in UnPickler, but (currently) not in Namer.

To be consistent with Scalac, we could additionally do it in Namer, and
then revert the change that switched things in matchingParams.

Alternatively, we can think about whether in Dotty, we want Java Object to
be represented internally as Any or Object. If we decide to keep it as
Object, then we would need to remove the conversion from UnPickler for
consistency.


Reply to this email directly or view it on GitHub
#345 (comment).

Martin Odersky
EPFL

@olhotak olhotak force-pushed the fix-javamethodtype branch from 03a37a5 to e4d9032 Compare February 1, 2015 19:02
@olhotak
Copy link
Contributor Author

olhotak commented Feb 1, 2015

I have updated the fix to be like scalac: Namer converts Object parameters in Java methods to Any. The switch in TypeComperer.matchingParams has been reverted.

I have some concern over the destructive update of symbol.info, but I did it that way for consistency with scalac. A (probably messy) alternative would be to change Object to Any somewhere inside the completer for the ValDef symbol for the parameter, if it has the JavaDefined and Param flags set.

… Any

Fixes two bugs needed for java-override test:

Namer was creating a MethodType instead of a JavaMethodType even though
the JavaDefined flag was set on the DefDef.

Following Scalac, Namer needs to convert Java method parameters
of type j.l.Object to s.Any.
@olhotak olhotak force-pushed the fix-javamethodtype branch from d9a013c to 4316f94 Compare February 7, 2015 18:28
@olhotak
Copy link
Contributor Author

olhotak commented Feb 7, 2015

Rebased to current master.

odersky added a commit that referenced this pull request Feb 11, 2015
Fix JavaMethodType creation and parameter matching of JavaMethodTypes
@odersky odersky merged commit 03a2c6e into scala:master Feb 11, 2015
tgodzik added a commit to tgodzik/scala3 that referenced this pull request Apr 29, 2025
Backport "Mix in the `productPrefix` hash statically in case class `hashCode`" to 3.3 LTS
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.

2 participants