Skip to content

Upper bound makes compiler infer Nothing #14218

Closed
@pweisenburger

Description

@pweisenburger

Hi, for the following code, the type of res0 is inferred as Z[String] in Scala 3:

scala> class Z[S](v: S => Unit)
scala> new Z((s: String) => ())
val res0: Z[String] = /* ... */

If you add an upper bound to the S type variable, the type of res1 is inferred as Z[Nothing]:

scala> class Z[S <: String](v: S => Unit)
scala> new Z((s: String) => ())
val res1: Z[Nothing] = /* ... */

Tested with Scala 3.1.0 and 3.1.1-RC1. This is also different from Scala 2, where the type in both cases is Z[String]. I would expect the upper bound not to change type inference and the compiler to infer the more useful type String.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions