Skip to content

Commit 41aaee4

Browse files
committed
Fix implcit use check and override check on repeared
1 parent da2e666 commit 41aaee4

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ object NullOpsDecorator {
3333
if (tp1s ne tp1) && (tp2s ne tp2) then
3434
tp.derivedAndType(tp1s, tp2s)
3535
else tp
36+
case tp @ TypeBounds(lo, hi) =>
37+
tp.derivedTypeBounds(strip(lo), strip(hi))
3638
case tp => tp
3739
}
3840
if tpStriped ne tpWiden then tpStriped else tp

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import transform.ValueClasses._
1111
import transform.TypeUtils._
1212
import transform.ContextFunctionResults._
1313
import Decorators._
14+
import NullOpsDecorator._
1415
import Definitions.MaxImplementedFunctionArity
1516
import scala.annotation.tailrec
1617

@@ -514,8 +515,11 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
514515
private def eraseArray(tp: Type)(using Context) = {
515516
val defn.ArrayOf(elemtp) = tp
516517
if (classify(elemtp).derivesFrom(defn.NullClass)) JavaArrayType(defn.ObjectType)
517-
else if (isUnboundedGeneric(elemtp) && !isJava) defn.ObjectType
518-
else JavaArrayType(erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(elemtp))
518+
else {
519+
val elemtp1 = if (ctx.explicitNulls) elemtp.stripNull else elemtp
520+
if (isUnboundedGeneric(elemtp1) && !isJava) defn.ObjectType
521+
else JavaArrayType(erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(elemtp1))
522+
}
519523
}
520524

521525
private def erasePair(tp: Type)(using Context): Type = {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import TreeInfo._
1515
import ProtoTypes._
1616
import Scopes._
1717
import CheckRealizable._
18+
import NullOpsDecorator._
1819
import ErrorReporting.errorTree
1920
import rewrites.Rewrites.patch
2021
import util.Spans.Span
@@ -765,17 +766,18 @@ trait Checking {
765766
* - it is defined in Predef
766767
* - it is the scala.reflect.Selectable.reflectiveSelectable conversion
767768
*/
768-
def checkImplicitConversionUseOK(sym: Symbol, pos: SrcPos)(using Context): Unit =
769+
def checkImplicitConversionUseOK(sym: Symbol, tpe: Type, posd: SrcPos)(using Context): Unit =
769770
if (sym.exists) {
770771
val conv =
771772
if (sym.isOneOf(GivenOrImplicit) || sym.info.isErroneous) sym
772773
else {
773774
assert(sym.name == nme.apply || ctx.reporter.errorsReported)
774775
sym.owner
775776
}
777+
val tpe1 = if ctx.explicitNulls then tpe.stripNull else tpe
776778
val conversionOK =
777779
conv.is(Synthetic) ||
778-
sym.info.finalResultType.classSymbols.exists(_.isLinkedWith(conv.owner)) ||
780+
tpe1.classSymbols.exists(_.isLinkedWith(conv.owner)) ||
779781
defn.isPredefClass(conv.owner) ||
780782
conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
781783
if (!conversionOK)
@@ -1238,7 +1240,7 @@ trait NoChecking extends ReChecking {
12381240
override def checkStable(tp: Type, pos: SrcPos, kind: String)(using Context): Unit = ()
12391241
override def checkClassType(tp: Type, pos: SrcPos, traitReq: Boolean, stablePrefixReq: Boolean)(using Context): Type = tp
12401242
override def checkImplicitConversionDefOK(sym: Symbol)(using Context): Unit = ()
1241-
override def checkImplicitConversionUseOK(sym: Symbol, pos: SrcPos)(using Context): Unit = ()
1243+
override def checkImplicitConversionUseOK(sym: Symbol, tpe: Type, posd: SrcPos)(using Context): Unit = ()
12421244
override def checkFeasibleParent(tp: Type, pos: SrcPos, where: => String = "")(using Context): Type = tp
12431245
override def checkInlineConformant(tpt: Tree, tree: Tree, sym: Symbol)(using Context): Unit = ()
12441246
override def checkNoAlphaConflict(stats: List[Tree])(using Context): Unit = ()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ class Typer extends Namer
35023502
case SearchSuccess(found: ExtMethodApply, _, _) =>
35033503
found // nothing to check or adapt for extension method applications
35043504
case SearchSuccess(found, ref, _) =>
3505-
checkImplicitConversionUseOK(ref.symbol, t.srcPos)
3505+
checkImplicitConversionUseOK(ref.symbol, found.typeOpt, t.srcPos)
35063506
withoutMode(Mode.ImplicitsEnabled)(readapt(found))
35073507
case failure: SearchFailure =>
35083508
fail(failure)

tests/explicit-nulls/pos/override-java-varargs/S.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// TODO: currently, OverridingParis cannot find bar in S1
2-
//
3-
// class S1 extends J {
4-
// override def foo(x: (String | Null)*): Unit = ???
5-
// override def bar(x: String | Null, y: (String | Null)*): Unit = ???
6-
// }
1+
class S1 extends J {
2+
override def foo(x: (String | Null)*): Unit = ???
3+
override def bar(x: String | Null, y: (String | Null)*): Unit = ???
4+
}
75

86
class S2 extends J {
97
override def foo(x: String*): Unit = ???

0 commit comments

Comments
 (0)