Skip to content

Fix #6336: Error on implicit conversions to AnyVal or AnyRef #8453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3140,7 +3140,9 @@ class Typer extends Namer
if (isFullyDefined(wtp, force = ForceDegree.all) &&
ctx.typerState.constraint.ne(prevConstraint)) readapt(tree)
else err.typeMismatch(tree, pt, failure)
if (ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType)
if ctx.mode.is(Mode.ImplicitsEnabled) && tree.typeOpt.isValueType then
if pt.isRef(defn.AnyValClass) || pt.isRef(defn.ObjectClass) then
ctx.error(em"the result of an implicit conversion must be more specific than $pt", tree.sourcePos)
inferView(tree, pt) match {
case SearchSuccess(found: ExtMethodApply, _, _) =>
found // nothing to check or adapt for extension method applications
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i6336.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test {
val a: AnyVal = "foo" // error
val b: AnyRef = 1 // error
}
3 changes: 0 additions & 3 deletions tests/pos/implicit-anyval-2.10.scala

This file was deleted.