Skip to content

Commit 8529885

Browse files
committed
Check no use of extension_ in definitions at Desugar
1 parent 2cd1092 commit 8529885

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,16 +985,21 @@ object desugar {
985985
/** The normalized name of `mdef`. This means
986986
* 1. Check that the name does not redefine a Scala core class.
987987
* If it does redefine, issue an error and return a mangled name instead of the original one.
988-
* 2. If the name is missing (this can be the case for instance definitions), invent one instead.
988+
* 2. Check that the name does not start with `extension_` unless the
989+
* method is an extension method.
990+
* 3. If the name is missing (this can be the case for instance definitions), invent one instead.
989991
*/
990992
def normalizeName(mdef: MemberDef, impl: Tree)(implicit ctx: Context): Name = {
991993
var name = mdef.name
992994
if (name.isEmpty) name = name.likeSpaced(inventGivenOrExtensionName(impl))
995+
def errPos = mdef.source.atSpan(mdef.nameSpan)
993996
if (ctx.owner == defn.ScalaPackageClass && defn.reservedScalaClassNames.contains(name.toTypeName)) {
994997
val kind = if (name.isTypeName) "class" else "object"
995-
ctx.error(IllegalRedefinitionOfStandardKind(kind, name), mdef.sourcePos)
998+
ctx.error(IllegalRedefinitionOfStandardKind(kind, name), errPos)
996999
name = name.errorName
9971000
}
1001+
if name.isExtensionName && !mdef.mods.is(Extension) then
1002+
ctx.error(em"illegal method name: $name may not start with `extension_`", errPos)
9981003
name
9991004
}
10001005

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,9 +1934,6 @@ class Typer extends Namer
19341934
val ddef2 = assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
19351935

19361936
checkSignatureRepeatedParam(sym)
1937-
if name.isExtensionName && !sym.is(Extension) then
1938-
ctx.error(em"illegal method name: $name may not start with `extension_`",
1939-
ddef.source.atSpan(ddef.nameSpan))
19401937
ddef2.setDefTree
19411938
//todo: make sure dependent method types do not depend on implicits or by-name params
19421939
}

0 commit comments

Comments
 (0)