@@ -3784,6 +3784,18 @@ 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 ! 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()
3787
3799
md.withMods(mods).setComment(in.getDocComment(start))
3788
3800
3789
3801
type ImportConstr = (Tree , List [ImportSelector ]) => Tree
@@ -4233,14 +4245,15 @@ object Parsers {
4233
4245
4234
4246
/** ClassDef ::= id ClassConstr TemplateOpt
4235
4247
*/
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)
4239
4252
4240
- def classDefRest (start : Offset , mods : Modifiers , name : TypeName ): TypeDef =
4253
+ def classDefRest (mods : Modifiers , name : TypeName ): TypeDef =
4241
4254
val constr = classConstr(if mods.is(Case ) then ParamOwner .CaseClass else ParamOwner .Class )
4242
4255
val templ = templateOpt(constr)
4243
- finalizeDef( TypeDef (name, templ), mods, start )
4256
+ TypeDef (name, templ)
4244
4257
4245
4258
/** ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsTermParamClauses
4246
4259
*/
@@ -4258,11 +4271,15 @@ object Parsers {
4258
4271
4259
4272
/** ObjectDef ::= id TemplateOpt
4260
4273
*/
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)
4266
4283
4267
4284
private def checkAccessOnly (mods : Modifiers , caseStr : String ): Modifiers =
4268
4285
// We allow `infix` and `into` on `enum` definitions.
@@ -4494,7 +4511,7 @@ object Parsers {
4494
4511
Template (constr, parents, Nil , EmptyValDef , Nil )
4495
4512
else if ! newSyntaxAllowed
4496
4513
|| 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,
4498
4515
// so old with-style syntax would not be allowed.
4499
4516
then
4500
4517
withTemplate(constr, parents)
0 commit comments