scala icon indicating copy to clipboard operation
scala copied to clipboard

Inconsistent behaviour when parameterising singleton type

Open tindzk opened this issue 7 years ago • 0 comments

The following example yields a type mismatch:

class StringSingletonList[T <: Singleton with String](values: List[T])
new StringSingletonList(List("a", "a"))
// inferred type arguments [String] do not conform to class StringSingletonList's type parameter bounds [T <: Singleton with String]

Strangely, the argument's type is inferred correctly:

List("a", "a"): List[_ <: Singleton with String] 
// res1: List[String] = List("a", "a")

These two declarations can be used as a workaround:

class StringSingletonList[T <: Singleton](values: List[T with String])
class StringSingletonList[T <: String](values: List[T with Singleton])

tindzk avatar Feb 12 '18 21:02 tindzk