Skip to content

Unsoundness for singletons? Regression from #16664 #17036

Open
@soronpo

Description

@soronpo

#16664 attempts to fix possible unsoundness issues, but I think it is too limiting.
Consider the following code that relies on singleton type from the parent class parameter.

Compiler version

3.3.1-RC1-bin-20230301-0df5ae2-NIGHTLY

Minimized code

def tuple1[D <: Int with Singleton](arg: D): Tuple1[D] = ???
class Container[T](arg: T)
class Extender[C <: Int with Singleton](val argC: C) extends Container(tuple1(argC)) //error

If we explicitly apply the type argument, this compiles fine:

def tuple1[D <: Int with Singleton](arg: D): Tuple1[D] = ???
class Container[T](arg: T)
class Extender[C <: Int with Singleton](val argC: C) extends Container[Tuple1[C]](tuple1(argC)) //no error

Output

The type of a class parent cannot refer to constructor parameters, but Container[Tuple1[(Extender.this.argC : C)]] refers to argC

Expectation

No error.
Note: Scala 2 also fails in the same situation (with a different error), but I don't see the how unsoundness is formed with singletons.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions