🌐 AI搜索 & 代理 主页
Skip to content

Commit 720c1cd

Browse files
committed
Check trivial trait args
1 parent 14888ce commit 720c1cd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ abstract class TreeBrowsers {
189189
}
190190
}
191191

192-
jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
192+
jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener {
193193
def valueChanged(e: javax.swing.event.TreeSelectionEvent): Unit = {
194194
textArea.setText(e.getPath().getLastPathComponent().toString)
195195
infoPanel.update(e.getPath().getLastPathComponent())

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
15871587
val decodedtpt = app.callee
15881588
val argssAreTrivial = argss == Nil || argss == ListOfNil
15891589

1590-
// we cannot avoid cyclic references with `initialize` here, because when type macros arrive,
1590+
// we cannot avoid cyclic references with `initialize` here, because when type macros arrive [sic],
15911591
// we'll have to check the probe for isTypeMacro anyways.
15921592
// therefore I think it's reasonable to trade a more specific "inherits itself" error
15931593
// for a generic, yet understandable "cyclic reference" error
@@ -1599,7 +1599,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
15991599

16001600
def cookIfNeeded(tpt: Tree) = if (context.unit.isJava) tpt modifyType rawToExistential else tpt
16011601
cookIfNeeded(if (probe.isTrait || inMixinPosition) {
1602-
if (!argssAreTrivial) {
1602+
if (!argss.isEmpty) {
16031603
if (probe.isTrait) ConstrArgsInParentWhichIsTraitError(encodedtpt, probe)
16041604
else () // a class in a mixin position - this warrants an error in `validateParentClasses`
16051605
// therefore here we do nothing, e.g. don't check that the # of ctor arguments

test/files/neg/t6805.check

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
t6805.scala:4: error: trait T is a trait; does not take constructor arguments
2+
class C extends T() // error
3+
^
4+
t6805.scala:7: error: trait T is a trait; does not take constructor arguments
5+
class Y extends X with T() // error
6+
^
7+
t6805.scala:10: error: trait T is a trait; does not take constructor arguments
8+
def t: T = new T() {} // error
9+
^
10+
t6805.scala:11: error: trait T is abstract; cannot be instantiated
11+
def u: T = new T() // error
12+
^
13+
t6805.scala:12: error: trait T is a trait; does not take constructor arguments
14+
def v: T = new X with T() // error
15+
^
16+
5 errors

test/files/neg/t6805.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
trait T
3+
4+
class C extends T() // error
5+
6+
class X
7+
class Y extends X with T() // error
8+
9+
object funcs {
10+
def t: T = new T() {} // error
11+
def u: T = new T() // error
12+
def v: T = new X with T() // error
13+
}

0 commit comments

Comments
 (0)