Skip to content

Named tuples are ambigious in (new) given syntax #22237

Open
@SrTobi

Description

@SrTobi

Compiler version

3.6.2 with -experimental

Minimized example

I'm currently implementing the new given syntax parsing for the intellij-scala plugin and I stumbled about this:

given (x: Int) = ???

Output

The compiler gives ')' expected, but ':' found as error message.

Expectation

According to the grammar the above code should be allowed
as named tuples are part of SimpleType.

Here the relevant grammar:

GivenDef          ::=  [id ':'] GivenSig
GivenSig          ::=  GivenImpl
                    |  '(' ')' '=>' GivenImpl
                    |  GivenConditional '=>' GivenSig
GivenImpl         ::=  GivenType ([‘=’ Expr] | TemplateBody)
                    |  ...
GivenConditional  ::=  DefTypeParamClause
                    |  DefTermParamClause
                    |  ...
                    |  GivenType 
GivenType         ::=  AnnotType1 {id [nl] AnnotType1}
AnnotType         ::=  SimpleType {Annotation}

DefTermParamClause and GivenType can look the same ((x: Int) for example)

I know that it doesn't make too much sense to have a named tuple in that position, still I'd like to know if that is intentional or not. Just so I don't have to implement and test our parser twice 😀

In the case that is should stay disallowed, I'd suggest changing the error message either to => expected after the ) or something like named tuples are not allowed in this position

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions