Skip to content

Annotations shadow singleton types #3564

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

There is a weird interaction between annotations and singleton types. In the following, the singleton type is lost when it shouldn't:

scala> def g(arg: "abc" @uncheckedVariance) = 1
def f(t: String @uncheckedVariance): Int

If "abc" is put in a type alias it's survives:

import scala.annotation.unchecked.uncheckedVariance
scala> type ST = "abc"
// defined alias type ST = abc
scala> def f(arg: ST @uncheckedVariance) = 1
def f(t: abc @uncheckedVariance): Int

This problems manifests itself when trying to create a case class with a singleton typed field, the copy method doesn't typecheck because of the above:

scala> case class Foo(s: "abc")
1 |case class Foo(s: "abc")
  |                       ^
  |                       found:    String @uncheckedVariance
  |                       required: String("abc")
  |

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