@@ -3078,10 +3078,13 @@ self =>
30783078 * }}}
30793079 */
30803080 def classDef (start : Offset , mods : Modifiers ): ClassDef = {
3081+ def isAfterLineEnd : Boolean = in.lastOffset < in.lineStartOffset && (in.lineStartOffset <= in.offset || in.lastOffset < in.lastLineStartOffset && in.lastLineStartOffset <= in.offset)
30813082 in.nextToken()
30823083 checkKeywordDefinition()
30833084 val nameOffset = in.offset
30843085 val name = identForType()
3086+ if (currentRun.isScala3 && in.token == LBRACKET && isAfterLineEnd)
3087+ deprecationWarning(in.offset, " type parameters should not follow newline" , " 2.13.7" )
30853088 atPos(start, if (name == tpnme.ERROR ) start else nameOffset) {
30863089 savingClassContextBounds {
30873090 val contextBoundBuf = new ListBuffer [Tree ]
@@ -3230,7 +3233,7 @@ self =>
32303233 deprecationWarning(in.offset, " Using `<:` for `extends` is deprecated" , since = " 2.12.5" )
32313234 true
32323235 }
3233- val (parents, self, body) = (
3236+ val (parents, self, body) =
32343237 if (in.token == EXTENDS || in.token == SUBTYPE && mods.isTrait && deprecatedUsage()) {
32353238 in.nextToken()
32363239 template()
@@ -3240,27 +3243,25 @@ self =>
32403243 val (self, body) = templateBodyOpt(parenMeansSyntaxError = mods.isTrait || name.isTermName)
32413244 (List (), self, body)
32423245 }
3243- )
3244- def anyvalConstructor () = (
3245- // Not a well-formed constructor, has to be finished later - see note
3246- // regarding AnyVal constructor in AddInterfaces.
3247- DefDef (NoMods , nme.CONSTRUCTOR , Nil , ListOfNil , TypeTree (), Block (Nil , literalUnit))
3248- )
3249- val parentPos = o2p(in.offset)
3250- val tstart1 = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart
3246+ // Not a well-formed constructor, has to be finished later - see note
3247+ // regarding AnyVal constructor in AddInterfaces.
3248+ def anyvalConstructor () = DefDef (NoMods , nme.CONSTRUCTOR , Nil , ListOfNil , TypeTree (), Block (Nil , literalUnit))
3249+ // tstart is the offset of the token after `class C[A]` (which may be LPAREN, EXTENDS, LBRACE).
3250+ // if there is no template body, then tstart may be in the next program element, so back up to just after the `class C[A]`.
3251+ val templateOffset = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart
3252+ val templatePos = o2p(templateOffset)
32513253
3252- // we can't easily check this later, because `gen.mkParents` adds the default AnyRef parent, and we need to warn based on what the user wrote
3253- if (name == nme.PACKAGEkw && parents.nonEmpty && settings.isScala3 )
3254- deprecationWarning(tstart, s " package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441); \n " +
3255- s " drop the `extends` clause or use a regular object instead " , " 3.0.0" )
3254+ // warn now if user wrote parents for package object; `gen.mkParents` adds AnyRef to parents
3255+ if (currentRun.isScala3 && name == nme.PACKAGEkw && ! parents.isEmpty )
3256+ deprecationWarning(tstart, """ package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
3257+ | drop the `extends` clause or use a regular object instead""" .stripMargin , " 3.0.0" )
32563258
3257- atPos(tstart1 ) {
3259+ atPos(templateOffset ) {
32583260 // Exclude only the 9 primitives plus AnyVal.
32593261 if (inScalaRootPackage && ScalaValueClassNames .contains(name))
32603262 Template (parents, self, anyvalConstructor() :: body)
32613263 else
3262- gen.mkTemplate(gen.mkParents(mods, parents, parentPos),
3263- self, constrMods, vparamss, body, o2p(tstart))
3264+ gen.mkTemplate(gen.mkParents(mods, parents, templatePos), self, constrMods, vparamss, body, templatePos)
32643265 }
32653266 }
32663267
0 commit comments