Skip to content

Commit f492867

Browse files
committed
Fix implcit use check and override check on repeared
1 parent f289a0a commit f492867

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
@@ -767,17 +768,18 @@ trait Checking {
767768
* - it is defined in Predef
768769
* - it is the scala.reflect.Selectable.reflectiveSelectable conversion
769770
*/
770-
def checkImplicitConversionUseOK(sym: Symbol, pos: SrcPos)(using Context): Unit =
771+
def checkImplicitConversionUseOK(sym: Symbol, tpe: Type, posd: SrcPos)(using Context): Unit =
771772
if (sym.exists) {
772773
val conv =
773774
if (sym.isOneOf(GivenOrImplicit) || sym.info.isErroneous) sym
774775
else {
775776
assert(sym.name == nme.apply || ctx.reporter.errorsReported)
776777
sym.owner
777778
}
779+
val tpe1 = if ctx.explicitNulls then tpe.stripNull else tpe
778780
val conversionOK =
779781
conv.is(Synthetic) ||
780-
sym.info.finalResultType.classSymbols.exists(_.isLinkedWith(conv.owner)) ||
782+
tpe1.classSymbols.exists(_.isLinkedWith(conv.owner)) ||
781783
defn.isPredefClass(conv.owner) ||
782784
conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
783785
if (!conversionOK)
@@ -1244,7 +1246,7 @@ trait NoChecking extends ReChecking {
12441246
override def checkStable(tp: Type, pos: SrcPos, kind: String)(using Context): Unit = ()
12451247
override def checkClassType(tp: Type, pos: SrcPos, traitReq: Boolean, stablePrefixReq: Boolean)(using Context): Type = tp
12461248
override def checkImplicitConversionDefOK(sym: Symbol)(using Context): Unit = ()
1247-
override def checkImplicitConversionUseOK(sym: Symbol, pos: SrcPos)(using Context): Unit = ()
1249+
override def checkImplicitConversionUseOK(sym: Symbol, tpe: Type, posd: SrcPos)(using Context): Unit = ()
12481250
override def checkFeasibleParent(tp: Type, pos: SrcPos, where: => String = "")(using Context): Type = tp
12491251
override def checkInlineConformant(tpt: Tree, tree: Tree, sym: Symbol)(using Context): Unit = ()
12501252
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)