-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label
Description
Anonymous givens should not be allowed. There is a dedicated error code for this
scala3/compiler/src/dotty/tools/dotc/reporting/messages.scala
Lines 2877 to 2884 in f310b11
| class AnonymousInstanceCannotBeEmpty(impl: untpd.Template)(using Context) | |
| extends SyntaxMsg(AnonymousInstanceCannotBeEmptyID) { | |
| def msg(using Context) = i"anonymous instance must implement a type or have at least one extension method" | |
| def explain(using Context) = | |
| i"""|Anonymous instances cannot be defined with an empty body. The block | |
| |`${impl.show}` should either contain an implemented type or at least one extension method. | |
| |""" | |
| } |
However it seems to be never triggered in
scala3/compiler/src/dotty/tools/dotc/ast/Desugar.scala
Lines 1349 to 1361 in f310b11
| /** Invent a name for an anonymous given of type or template `impl`. */ | |
| def inventGivenName(impl: Tree)(using Context): SimpleName = | |
| val str = impl match | |
| case impl: Template => | |
| if impl.parents.isEmpty then | |
| report.error(AnonymousInstanceCannotBeEmpty(impl), impl.srcPos) | |
| nme.ERROR.toString | |
| else | |
| impl.parents.map(inventTypeName(_)).mkString("given_", "_", "") | |
| case impl: Tree => | |
| "given_" ++ inventTypeName(impl) | |
| str.toTermName.asSimpleName | |
Compiler version
3.7.4
3.8.1-nightly
Minimized code
given {}The question is should anonymous refinements be allowed:
given {def foo: Int} = ???
given {def bar: Int} = ???Both compile but produce the same name leading to other compilation error
Output
Compiles
Expectation
Metadata
Metadata
Assignees
Labels
itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label