@@ -3784,6 +3784,17 @@ object Parsers {
3784
3784
/* -------- DEFS ------------------------------------------- */
3785
3785
3786
3786
def finalizeDef (md : MemberDef , mods : Modifiers , start : Int ): md.ThisTree [Untyped ] =
3787
+ def checkName (): Unit =
3788
+ def checkName (name : Name ): Unit =
3789
+ if ! Chars .isOperatorPart(name.firstCodePoint) // warn a_: not ::
3790
+ && name.endsWith(" :" )
3791
+ then
3792
+ report.warning(AmbiguousTemplateName (md), md.namePos)
3793
+ md match
3794
+ case md @ TypeDef (name, impl : Template ) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3795
+ case md @ ModuleDef (name, impl) if impl.body.isEmpty && ! md.isBackquoted => checkName(name)
3796
+ case _ =>
3797
+ checkName()
3787
3798
md.withMods(mods).setComment(in.getDocComment(start))
3788
3799
3789
3800
type ImportConstr = (Tree , List [ImportSelector ]) => Tree
@@ -4233,14 +4244,15 @@ object Parsers {
4233
4244
4234
4245
/** ClassDef ::= id ClassConstr TemplateOpt
4235
4246
*/
4236
- def classDef (start : Offset , mods : Modifiers ): TypeDef = atSpan(start, nameStart) {
4237
- classDefRest(start, mods, ident().toTypeName)
4238
- }
4247
+ def classDef (start : Offset , mods : Modifiers ): TypeDef =
4248
+ val td = atSpan(start, nameStart):
4249
+ classDefRest(mods, ident().toTypeName)
4250
+ finalizeDef(td, mods, start)
4239
4251
4240
- def classDefRest (start : Offset , mods : Modifiers , name : TypeName ): TypeDef =
4252
+ def classDefRest (mods : Modifiers , name : TypeName ): TypeDef =
4241
4253
val constr = classConstr(if mods.is(Case ) then ParamOwner .CaseClass else ParamOwner .Class )
4242
4254
val templ = templateOpt(constr)
4243
- finalizeDef( TypeDef (name, templ), mods, start )
4255
+ TypeDef (name, templ)
4244
4256
4245
4257
/** ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsTermParamClauses
4246
4258
*/
@@ -4258,11 +4270,15 @@ object Parsers {
4258
4270
4259
4271
/** ObjectDef ::= id TemplateOpt
4260
4272
*/
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
- }
4273
+ def objectDef (start : Offset , mods : Modifiers ): ModuleDef =
4274
+ val md = atSpan(start, nameStart):
4275
+ val nameIdent = termIdent()
4276
+ val templ = templateOpt(emptyConstructor)
4277
+ ModuleDef (nameIdent.name.asTermName, templ)
4278
+ .tap: md =>
4279
+ if nameIdent.isBackquoted then
4280
+ md.pushAttachment(Backquoted , ())
4281
+ finalizeDef(md, mods, start)
4266
4282
4267
4283
private def checkAccessOnly (mods : Modifiers , caseStr : String ): Modifiers =
4268
4284
// We allow `infix` and `into` on `enum` definitions.
0 commit comments