@@ -3862,6 +3862,18 @@ object Parsers {
38623862/* -------- DEFS ------------------------------------------- */
38633863
38643864 def finalizeDef (md : MemberDef , mods : Modifiers , start : Int ): md.ThisTree [Untyped ] =
3865+ def checkName (): Unit =
3866+ def checkName (name : Name ): Unit =
3867+ if ! name.isEmpty
3868+ && ! Chars .isOperatorPart(name.firstCodePoint) // warn a_: not ::
3869+ && name.endsWith(" :" )
3870+ then
3871+ report.warning(AmbiguousTemplateName (md), md.namePos)
3872+ md match
3873+ case md @ TypeDef (name, impl : Template ) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3874+ case md @ ModuleDef (name, impl) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3875+ case _ =>
3876+ checkName()
38653877 md.withMods(mods).setComment(in.getDocComment(start))
38663878
38673879 type ImportConstr = (Tree , List [ImportSelector ]) => Tree
@@ -4311,14 +4323,15 @@ object Parsers {
43114323
43124324 /** ClassDef ::= id ClassConstr TemplateOpt
43134325 */
4314- def classDef (start : Offset , mods : Modifiers ): TypeDef = atSpan(start, nameStart) {
4315- classDefRest(start, mods, ident().toTypeName)
4316- }
4326+ def classDef (start : Offset , mods : Modifiers ): TypeDef =
4327+ val td = atSpan(start, nameStart):
4328+ classDefRest(mods, ident().toTypeName)
4329+ finalizeDef(td, mods, start)
43174330
4318- def classDefRest (start : Offset , mods : Modifiers , name : TypeName ): TypeDef =
4331+ def classDefRest (mods : Modifiers , name : TypeName ): TypeDef =
43194332 val constr = classConstr(if mods.is(Case ) then ParamOwner .CaseClass else ParamOwner .Class )
43204333 val templ = templateOpt(constr)
4321- finalizeDef( TypeDef (name, templ), mods, start )
4334+ TypeDef (name, templ)
43224335
43234336 /** ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsTermParamClauses
43244337 */
@@ -4336,11 +4349,15 @@ object Parsers {
43364349
43374350 /** ObjectDef ::= id TemplateOpt
43384351 */
4339- def objectDef (start : Offset , mods : Modifiers ): ModuleDef = atSpan(start, nameStart) {
4340- val name = ident()
4341- val templ = templateOpt(emptyConstructor)
4342- finalizeDef(ModuleDef (name, templ), mods, start)
4343- }
4352+ def objectDef (start : Offset , mods : Modifiers ): ModuleDef =
4353+ val md = atSpan(start, nameStart):
4354+ val nameIdent = termIdent()
4355+ val templ = templateOpt(emptyConstructor)
4356+ ModuleDef (nameIdent.name.asTermName, templ)
4357+ .tap: md =>
4358+ if nameIdent.isBackquoted then
4359+ md.pushAttachment(Backquoted , ())
4360+ finalizeDef(md, mods, start)
43444361
43454362 private def checkAccessOnly (mods : Modifiers , caseStr : String ): Modifiers =
43464363 // We allow `infix` and `into` on `enum` definitions.
@@ -4572,7 +4589,7 @@ object Parsers {
45724589 Template (constr, parents, Nil , EmptyValDef , Nil )
45734590 else if ! newSyntaxAllowed
45744591 || in.token == WITH && tparams.isEmpty && vparamss.isEmpty
4575- // if new syntax is still allowed and there are parameters, they mist be new style conditions,
4592+ // if new syntax is still allowed and there are parameters, they must be new style conditions,
45764593 // so old with-style syntax would not be allowed.
45774594 then
45784595 withTemplate(constr, parents)
0 commit comments