From 927e1508af213f89eac1d8297ec766defb263763 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 26 Aug 2019 18:22:31 +0200 Subject: [PATCH] Fix #7103: Accept backquoted `as` as the name of a given --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 2 +- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- tests/pos/i7103.scala | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i7103.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index bd3938b1aeaa..f678d8e0cfe9 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -957,7 +957,7 @@ object desugar { case Some(DefDef(name, _, (vparam :: _) :: _, _, _)) => s"${name}_of_${inventTypeName(vparam.tpt)}" case _ => - ctx.error(i"anonymous instance must have `for` part or must define at least one extension method", impl.sourcePos) + ctx.error(i"anonymous instance must have `as` part or must define at least one extension method", impl.sourcePos) nme.ERROR.toString } else diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 4b1bc583c746..b6cf173a1227 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2873,7 +2873,7 @@ object Parsers { */ def instanceDef(newStyle: Boolean, start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) { var mods1 = addMod(mods, instanceMod) - val name = if (isIdent && (!newStyle || in.name != nme.as)) ident() else EmptyTermName + val name = if (isIdent && !(newStyle && isIdent(nme.as))) ident() else EmptyTermName val tparams = typeParamClauseOpt(ParamOwner.Def) var leadingParamss = if (in.token == LPAREN) diff --git a/tests/pos/i7103.scala b/tests/pos/i7103.scala new file mode 100644 index 000000000000..edc0f5220ead --- /dev/null +++ b/tests/pos/i7103.scala @@ -0,0 +1,3 @@ +class X +object X extends X +given `as` as X = X \ No newline at end of file