Skip to content

AnyRef and AnyVal should be disjoint #6335

@OlivierBlanvillain

Description

@OlivierBlanvillain

Looking at the documentation on AnyRef: "Class AnyRef is the root class of all reference types. All types except the value types descend from this class", I believe the following shouldn't compile:

case class Boo(i: Int) extends AnyVal                                 
val b: AnyRef = Boo(1)   

dottc accepts that code, but I think it should complain in the same way that scalac does:

scala> val a: AnyRef = Boo(1)                                                

                          ^
       error: type mismatch;
        found   : Boo
        required: AnyRef
       Note that Boo extends Any, not AnyRef.                                
       Such types can participate in value classes, but instances            
       cannot appear in singleton types or in reference comparisons.    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions