@@ -3784,6 +3784,18 @@ object Parsers {
37843784/* -------- DEFS ------------------------------------------- */
37853785
37863786 def finalizeDef (md : MemberDef , mods : Modifiers , start : Int ): md.ThisTree [Untyped ] =
3787+ def checkName (): Unit =
3788+ def checkName (name : Name ): Unit =
3789+ if ! name.isEmpty
3790+ && ! Chars .isOperatorPart(name.firstCodePoint) // warn a_: not ::
3791+ && name.endsWith(" :" )
3792+ then
3793+ report.warning(AmbiguousTemplateName (md), md.namePos)
3794+ md match
3795+ case md @ TypeDef (name, impl : Template ) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3796+ case md @ ModuleDef (name, impl) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3797+ case _ =>
3798+ checkName()
37873799 md.withMods(mods).setComment(in.getDocComment(start))
37883800
37893801 type ImportConstr = (Tree , List [ImportSelector ]) => Tree
@@ -4233,14 +4245,15 @@ object Parsers {
42334245
42344246 /** ClassDef ::= id ClassConstr TemplateOpt
42354247 */
4236- def classDef (start : Offset , mods : Modifiers ): TypeDef = atSpan(start, nameStart) {
4237- classDefRest(start, mods, ident().toTypeName)
4238- }
4248+ def classDef (start : Offset , mods : Modifiers ): TypeDef =
4249+ val td = atSpan(start, nameStart):
4250+ classDefRest(mods, ident().toTypeName)
4251+ finalizeDef(td, mods, start)
42394252
4240- def classDefRest (start : Offset , mods : Modifiers , name : TypeName ): TypeDef =
4253+ def classDefRest (mods : Modifiers , name : TypeName ): TypeDef =
42414254 val constr = classConstr(if mods.is(Case ) then ParamOwner .CaseClass else ParamOwner .Class )
42424255 val templ = templateOpt(constr)
4243- finalizeDef( TypeDef (name, templ), mods, start )
4256+ TypeDef (name, templ)
42444257
42454258 /** ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsTermParamClauses
42464259 */
@@ -4258,11 +4271,15 @@ object Parsers {
42584271
42594272 /** ObjectDef ::= id TemplateOpt
42604273 */
4261- def objectDef (start : Offset , mods : Modifiers ): ModuleDef = atSpan(start, nameStart) {
4262- val name = ident()
4263- val templ = templateOpt(emptyConstructor)
4264- finalizeDef(ModuleDef (name, templ), mods, start)
4265- }
4274+ def objectDef (start : Offset , mods : Modifiers ): ModuleDef =
4275+ val md = atSpan(start, nameStart):
4276+ val nameIdent = termIdent()
4277+ val templ = templateOpt(emptyConstructor)
4278+ ModuleDef (nameIdent.name.asTermName, templ)
4279+ .tap: md =>
4280+ if nameIdent.isBackquoted then
4281+ md.pushAttachment(Backquoted , ())
4282+ finalizeDef(md, mods, start)
42664283
42674284 private def checkAccessOnly (mods : Modifiers , caseStr : String ): Modifiers =
42684285 // We allow `infix` and `into` on `enum` definitions.
@@ -4494,7 +4511,7 @@ object Parsers {
44944511 Template (constr, parents, Nil , EmptyValDef , Nil )
44954512 else if ! newSyntaxAllowed
44964513 || in.token == WITH && tparams.isEmpty && vparamss.isEmpty
4497- // if new syntax is still allowed and there are parameters, they mist be new style conditions,
4514+ // if new syntax is still allowed and there are parameters, they must be new style conditions,
44984515 // so old with-style syntax would not be allowed.
44994516 then
45004517 withTemplate(constr, parents)
0 commit comments