Skip to content

Commit 492cae7

Browse files
authored
Merge pull request #8453 from dotty-staging/fix-#6336
Fix #6336: Error on implicit conversions to AnyVal or AnyRef
2 parents 83e6270 + 0adae53 commit 492cae7

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3140,7 +3140,9 @@ class Typer extends Namer
31403140
if (isFullyDefined(wtp, force = ForceDegree.all) &&
31413141
ctx.typerState.constraint.ne(prevConstraint)) readapt(tree)
31423142
else err.typeMismatch(tree, pt, failure)
3143-
if (ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType)
3143+
if ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType then
3144+
if pt.isRef(defn.AnyValClass) || pt.isRef(defn.ObjectClass) then
3145+
ctx.error(em"the result of an implicit conversion must be more specific than $pt", tree.sourcePos)
31443146
inferView(tree, pt) match {
31453147
case SearchSuccess(found: ExtMethodApply, _, _) =>
31463148
found // nothing to check or adapt for extension method applications

tests/neg/i6336.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
val a: AnyVal = "foo" // error
3+
val b: AnyRef = 1 // error
4+
}

tests/pos/implicit-anyval-2.10.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)