Skip to content

explicit declaration of return type with compound type parameter fails #7647

@scabug

Description

@scabug

From StackOverflow: http://stackoverflow.com/questions/17559687/compile-time-constraints-on-the-order-of-function-composition-in-scala

Compilation fails for a method that explicitly declares a return a type with a compound type parameter, but succeeds and infers the same type when the return type is not explicitly declared:

scala> trait Foo[A] { def bar[B](b: B): Foo[A with B] }
defined trait Foo
 
scala> def baz[A](foo: Foo[A]) = foo bar 1
baz: [A](foo: Foo[A])Foo[A with Int]
 
scala> def baz[A](foo: Foo[A]): Foo[A with Int] = foo bar 1
<console>:8: error: type mismatch;
 found   : Int(1)
 required: Nothing
       def baz[A](foo: Foo[A]): Foo[A with Int] = foo bar 1
                                                          ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)typer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions