Skip to content

existentials in structural type signatures #4867

Open
@scabug

Description

@scabug

This works:

scala> var x: AnyVal { def *(other: Int): Int } = _
x: AnyVal{def *(other: Int): Int} = null

scala> x = 5
x: AnyVal{def *(other: Int): Int} = 5

This doesn't, nor obviously does any more useful attempt to apply existentials (more useful than the Int identity that is.)

scala> var x: AnyVal { def *(other: T forSome { type T >: Int <: Int }): Int } = _
x: AnyVal{def *(other: T forSome { type T >: Int <: Int }): Int} = null

scala> x = 5
<console>:8: error: type mismatch;
 found   : Int(5)
 required: AnyVal{def *(other: T forSome { type T >: Int <: Int }): Int}
       x = 5
           ^

Putting the shoe back on the other foot, this works:

scala> type SomeT[Bound] = T forSome { type T >: Bound <: Bound }
defined type alias SomeT

scala> var x: AnyVal { def *(other: SomeT[Int]): Int } = _
x: AnyVal{def *(other: SomeT[Int]): Int} = null

scala> x = 5
x: AnyVal{def *(other: SomeT[Int]): Int} = 5

So there are a lot of interesting questions here, but there is little doubt that at the least, it is a bug that it works with an alias but not by skipping the alias and using the identical expansion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions