Skip to content

Commit fe0df69

Browse files
authored
Merge pull request scala#9794 from som-snytt/issue/12470
2 parents 622d55e + 06d7dcf commit fe0df69

20 files changed

+96
-80
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
478478
def isAtProgramPoint(lbl: asm.Label): Boolean = {
479479
(lastInsn match { case labnode: asm.tree.LabelNode => (labnode.getLabel == lbl); case _ => false } )
480480
}
481-
def lineNumber(tree: Tree): Unit = {
482-
if (!emitLines || !tree.pos.isDefined) return
481+
def lineNumber(tree: Tree): Unit = if (emitLines && tree.pos.isDefined) {
483482
val nr = tree.pos.finalPosition.line
484483
if (nr != lastEmittedLineNr) {
485484
lastEmittedLineNr = nr

src/testkit/scala/tools/testkit/BytecodeTesting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import scala.tools.testkit.ASMConverters._
3232

3333
trait BytecodeTesting extends ClearAfterClass {
3434
/**
35-
* Overwrite to set additional compiler flags
35+
* Override to set additional compiler flags.
3636
*/
3737
def compilerArgs = ""
3838

test/files/run/dynamic-applyDynamic.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of typer]] // newSource1.scala
22
[0:67]package [0:0]<empty> {
3-
[0:67]object X extends [9:67][67]scala.AnyRef {
4-
[67]def <init>(): [9]X.type = [67]{
5-
[67][67][67]X.super.<init>();
3+
[0:67]object X extends [9:67][9]scala.AnyRef {
4+
[9]def <init>(): [9]X.type = [9]{
5+
[9][9][9]X.super.<init>();
66
[9]()
77
};
88
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();

test/files/run/dynamic-applyDynamicNamed.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of typer]] // newSource1.scala
22
[0:97]package [0:0]<empty> {
3-
[0:97]object X extends [9:97][97]scala.AnyRef {
4-
[97]def <init>(): [9]X.type = [97]{
5-
[97][97][97]X.super.<init>();
3+
[0:97]object X extends [9:97][9]scala.AnyRef {
4+
[9]def <init>(): [9]X.type = [9]{
5+
[9][9][9]X.super.<init>();
66
[9]()
77
};
88
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();

test/files/run/dynamic-selectDynamic.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of typer]] // newSource1.scala
22
[0:50]package [0:0]<empty> {
3-
[0:50]object X extends [9:50][50]scala.AnyRef {
4-
[50]def <init>(): [9]X.type = [50]{
5-
[50][50][50]X.super.<init>();
3+
[0:50]object X extends [9:50][9]scala.AnyRef {
4+
[9]def <init>(): [9]X.type = [9]{
5+
[9][9][9]X.super.<init>();
66
[9]()
77
};
88
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();

test/files/run/dynamic-updateDynamic.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of typer]] // newSource1.scala
22
[0:69]package [0:0]<empty> {
3-
[0:69]object X extends [9:69][69]scala.AnyRef {
4-
[69]def <init>(): [9]X.type = [69]{
5-
[69][69][69]X.super.<init>();
3+
[0:69]object X extends [9:69][9]scala.AnyRef {
4+
[9]def <init>(): [9]X.type = [9]{
5+
[9][9][9]X.super.<init>();
66
[9]()
77
};
88
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();

test/files/run/existential-rangepos.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of patmat]] // newSource1.scala
22
[0:76]package [0:0]<empty> {
3-
[0:76]abstract class A[[17:18]T[17:18]] extends [20:76][76]scala.AnyRef {
4-
[76]def <init>(): [20]A[T] = [76]{
5-
[76][76][76]A.super.<init>();
3+
[0:76]abstract class A[[17:18]T[17:18]] extends [20:76][20]scala.AnyRef {
4+
[20]def <init>(): [20]A[T] = [20]{
5+
[20][20][20]A.super.<init>();
66
[20]()
77
};
88
[24:51]private[this] val foo: [28]Set[_ <: T] = [47:51]null;

test/files/run/literals-parsing.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[syntax trees at end of parser]] // newSource1.scala
22
[0:161]package [0:0]<empty> {
3-
[0:161]abstract trait T extends [8:161][161]scala.AnyRef {
3+
[0:161]abstract trait T extends [8:161][8]scala.AnyRef {
44
[8]def $init$() = [8]{
55
[8]()
66
};

test/files/run/sd187.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of patmat]] // newSource1.scala
22
[1:2302]package [1:1]<empty> {
3-
[1:2302]class C extends [9:2302][2302]scala.AnyRef {
4-
[2302]def <init>(): [9]C = [2302]{
5-
[2302][2302][2302]C.super.<init>();
3+
[1:2302]class C extends [9:2302][9]scala.AnyRef {
4+
[9]def <init>(): [9]C = [9]{
5+
[9][9][9]C.super.<init>();
66
[9]()
77
};
88
[103:904]def commonSubPattern([124:130]x: [127:130]<type: [127:130]scala.Any>): [107]AnyVal = [206:220]{

0 commit comments

Comments
 (0)