Skip to content

Implicit conversions to Any/AnyVal/AnyRef should be disallowed #6336

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions