Skip to content

Parsing inconsistency of def vs. given with structural refinement #22946

@TomasMikula

Description

@TomasMikula

Compiler version

3.6.4

Minimized code

class Foo { type T }

// `def` works fine
def foo[A]: Foo { type T = A } =
  new Foo { type T = A }

// `given` does not: Syntax error: 'with' expected, but '{' found
given bar[A]: Foo { type T = A } =
  new Foo { type T = A }

// workaround: add parentheses
given baz[A]: (Foo { type T = A }) =
  new Foo { type T = A }

Output

-- [E040] Syntax Error: Test.scala:8:18 ----------------------------------------
8 |given bar[A]: Foo { type T = A } =
  |                  ^
  |                  'with' expected, but '{' found
-- [E040] Syntax Error: Test.scala:14:0 ----------------------------------------
14 |
   |^
   |'}' expected, but eof found
2 errors found

Expectation

I would expect def and given syntax to be consistent as much as possible.

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