Skip to content

Commit 536b978

Browse files
committed
error on concrete val in universal trait
see neg/anytrait.scala
1 parent d7c1de8 commit 536b978

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

+6
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
13401340
notAllowed(s"redefinition of $name method. See SIP-15, criterion 4.")
13411341
else if (stat.symbol != null && stat.symbol.isParamAccessor)
13421342
notAllowed("additional parameter")
1343+
// concrete accessor (getter) in trait corresponds to a field definition (neg/anytrait.scala)
1344+
// TODO: only reject accessors that actually give rise to field (e.g., a constant-type val is fine)
1345+
else if (!isValueClass && stat.symbol.isAccessor && !stat.symbol.isDeferred)
1346+
notAllowed("field definition")
13431347
checkEphemeralDeep.traverse(rhs)
1348+
// for value class or "exotic" vals in traits
1349+
// (traits don't receive ValDefs for regular vals until fields phase -- well, except for early initialized/lazy vals)
13441350
case _: ValDef =>
13451351
notAllowed("field definition")
13461352
case _: ModuleDef =>

0 commit comments

Comments
 (0)