Skip to content

Function type ascriptions discrepancy between parser and syntax.  #15260

Open
@odersky

Description

@odersky

Compiler version

3.2

Minimized example

def f[T](x: T): T = x
val x1 = (f: Int => Int)      // ok, but should be error
val x2 = f: Int => Int       // error

Output

3 |val x2 = f: Int => Int
  |                ^
  |parentheses are required around the parameter of a lambda
  |This construct can be rewritten automatically under -rewrite -source 3.0-migration.```

Expectation

According to the syntax, both lines 2 and 3 should give an error since type ascriptions require an InfixType. Line 3 gives an error because the compiler thinks it's a lambda. Line 2 compiles without error, but should ideally give an error like this:

2 |val x1 = (f: Int => Int)
  |             ^^^^^^^^^^
  |          function type in type ascription must be enclosed in parentheses

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions