Dotty: Implicit conversions to Any/AnyVal/AnyRef should be disallowed

Created on 18 Apr 2019  路  1Comment  路  Source: lampepfl/dotty

According to the documentation on AnyVal, Strings are not value types, so I believe the following shouldn't compile:

val a: AnyVal = "foo"

Here is how scalac complains:

$ echo 'val a: AnyVal = ""' | scala
Welcome to Scala 2.13.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_201).
scala> val a: AnyVal = ""
                       ^
       error: the result type of an implicit conversion must be more specific than AnyVal
$ echo 'val a: AnyVal = ""' | scala -Yno-predef
Welcome to Scala 2.13.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_201).
scala> val a: AnyVal = ""
                       ^
       error: type mismatch;
        found   : String("")
        required: AnyVal
typer scala2 bug

Most helpful comment

It inserts Predef.augmentString as an implicit conversion. Once we move to extension methods this problem is gone. Until then it would be good to bring back the restrictions that implicit conversions can't convert to Any, AnyVal, or AnyRef.

>All comments

It inserts Predef.augmentString as an implicit conversion. Once we move to extension methods this problem is gone. Until then it would be good to bring back the restrictions that implicit conversions can't convert to Any, AnyVal, or AnyRef.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

odersky picture odersky  路  126Comments

japgolly picture japgolly  路  55Comments

odersky picture odersky  路  114Comments

lihaoyi picture lihaoyi  路  30Comments

megri picture megri  路  29Comments