Skip to content

Commit c3233d2

Browse files
Merge pull request #7106 from dotty-staging/fix-#7103
Fix #7103: Accept backquoted `as` as the name of a given
2 parents 26217ce + 927e150 commit c3233d2

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ object desugar {
957957
case Some(DefDef(name, _, (vparam :: _) :: _, _, _)) =>
958958
s"${name}_of_${inventTypeName(vparam.tpt)}"
959959
case _ =>
960-
ctx.error(i"anonymous instance must have `for` part or must define at least one extension method", impl.sourcePos)
960+
ctx.error(i"anonymous instance must have `as` part or must define at least one extension method", impl.sourcePos)
961961
nme.ERROR.toString
962962
}
963963
else

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,7 @@ object Parsers {
28732873
*/
28742874
def instanceDef(newStyle: Boolean, start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) {
28752875
var mods1 = addMod(mods, instanceMod)
2876-
val name = if (isIdent && (!newStyle || in.name != nme.as)) ident() else EmptyTermName
2876+
val name = if (isIdent && !(newStyle && isIdent(nme.as))) ident() else EmptyTermName
28772877
val tparams = typeParamClauseOpt(ParamOwner.Def)
28782878
var leadingParamss =
28792879
if (in.token == LPAREN)

tests/pos/i7103.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class X
2+
object X extends X
3+
given `as` as X = X

0 commit comments

Comments
 (0)