Skip to content

fix #10884: eliminate JavaMethodType from exported info #10948

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
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,19 @@ object Types {
else funType
}

final def dropJavaMethod(using Context): Type = this match
case pt: PolyType => pt.derivedLambdaType(resType = pt.resType.dropJavaMethod)

case mt: MethodType =>
if mt.isJavaMethod then
MethodType.apply(mt.paramNames, mt.paramInfos, mt.resType.dropJavaMethod)
else
mt.derivedLambdaType(resType = mt.resType.dropJavaMethod)

case _ => this

end dropJavaMethod

/** The signature of this type. This is by default NotAMethod,
* but is overridden for PolyTypes, MethodTypes, and TermRef types.
* (the reason why we deviate from the "final-method-with-pattern-match-in-base-class"
Expand Down
11 changes: 2 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,8 @@ object ErrorReporting {

/** A subtype log explaining why `found` does not conform to `expected` */
def whyNoMatchStr(found: Type, expected: Type): String = {
def dropJavaMethod(tp: Type): Type = tp match {
case tp: PolyType =>
tp.derivedLambdaType(resType = dropJavaMethod(tp.resultType))
case tp: MethodType if tp.isJavaMethod =>
MethodType(tp.paramNames, tp.paramInfos, dropJavaMethod(tp.resultType))
case tp => tp
}
val found1 = dropJavaMethod(found)
val expected1 = dropJavaMethod(expected)
val found1 = found.dropJavaMethod
val expected1 = expected.dropJavaMethod
if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
i"""
|(Note that Scala's and Java's representation of this type differs)"""
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ class Namer { typer: Typer =>
if sym.isStableMember && sym.isPublic && !refersToPrivate(path.tpe) then
(StableRealizable, ExprType(path.tpe.select(sym)))
else
(EmptyFlags, mbr.info.ensureMethodic)
(EmptyFlags, mbr.info.ensureMethodic.dropJavaMethod)
var mbrFlags = Exported | Method | Final | maybeStable | sym.flags & RetainedExportFlags
if sym.is(ExtensionMethod) then mbrFlags |= ExtensionMethod
val forwarderName = checkNoConflict(alias, isPrivate = false, span)
Expand Down
7 changes: 7 additions & 0 deletions tests/run/i10884/JavaExporter_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.util.Arrays;

public class JavaExporter_1 {
public static String varargExample(String... args) {
return Arrays.toString(args);
}
}
7 changes: 7 additions & 0 deletions tests/run/i10884/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Exporter:
export JavaExporter_1._

import Exporter._

@main def Test =
println(varargExample("a", "b", "c"))