Skip to content

Commit c878f92

Browse files
committed
fix #10884: eliminate JavaMethodType from exported info
1 parent ca02d83 commit c878f92

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
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/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)