Skip to content

Commit b1dafb7

Browse files
authored
Merge pull request #10948 from dotty-staging/fix-10884
fix #10884: eliminate JavaMethodType from exported info
2 parents ca02d83 + 509e356 commit b1dafb7

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,19 @@ object Types {
17161716
else funType
17171717
}
17181718

1719+
final def dropJavaMethod(using Context): Type = this match
1720+
case pt: PolyType => pt.derivedLambdaType(resType = pt.resType.dropJavaMethod)
1721+
1722+
case mt: MethodType =>
1723+
if mt.isJavaMethod then
1724+
MethodType.apply(mt.paramNames, mt.paramInfos, mt.resType.dropJavaMethod)
1725+
else
1726+
mt.derivedLambdaType(resType = mt.resType.dropJavaMethod)
1727+
1728+
case _ => this
1729+
1730+
end dropJavaMethod
1731+
17191732
/** The signature of this type. This is by default NotAMethod,
17201733
* but is overridden for PolyTypes, MethodTypes, and TermRef types.
17211734
* (the reason why we deviate from the "final-method-with-pattern-match-in-base-class"

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,8 @@ object ErrorReporting {
111111

112112
/** A subtype log explaining why `found` does not conform to `expected` */
113113
def whyNoMatchStr(found: Type, expected: Type): String = {
114-
def dropJavaMethod(tp: Type): Type = tp match {
115-
case tp: PolyType =>
116-
tp.derivedLambdaType(resType = dropJavaMethod(tp.resultType))
117-
case tp: MethodType if tp.isJavaMethod =>
118-
MethodType(tp.paramNames, tp.paramInfos, dropJavaMethod(tp.resultType))
119-
case tp => tp
120-
}
121-
val found1 = dropJavaMethod(found)
122-
val expected1 = dropJavaMethod(expected)
114+
val found1 = found.dropJavaMethod
115+
val expected1 = expected.dropJavaMethod
123116
if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
124117
i"""
125118
|(Note that Scala's and Java's representation of this type differs)"""

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ class Namer { typer: Typer =>
10241024
if sym.isStableMember && sym.isPublic && !refersToPrivate(path.tpe) then
10251025
(StableRealizable, ExprType(path.tpe.select(sym)))
10261026
else
1027-
(EmptyFlags, mbr.info.ensureMethodic)
1027+
(EmptyFlags, mbr.info.ensureMethodic.dropJavaMethod)
10281028
var mbrFlags = Exported | Method | Final | maybeStable | sym.flags & RetainedExportFlags
10291029
if sym.is(ExtensionMethod) then mbrFlags |= ExtensionMethod
10301030
val forwarderName = checkNoConflict(alias, isPrivate = false, span)

tests/run/i10884/JavaExporter_1.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java.util.Arrays;
2+
3+
public class JavaExporter_1 {
4+
public static String varargExample(String... args) {
5+
return Arrays.toString(args);
6+
}
7+
}

tests/run/i10884/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Exporter:
2+
export JavaExporter_1._
3+
4+
import Exporter._
5+
6+
@main def Test =
7+
println(varargExample("a", "b", "c"))

0 commit comments

Comments
 (0)