Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41aafb7

Browse filesBrowse files
committed
Check trivial trait args
1 parent 8f9df67 commit 41aafb7
Copy full SHA for 41aafb7

File tree

7 files changed

+36
-9
lines changed
Filter options

7 files changed

+36
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/compiler/scala/tools/nsc/typechecker/Typers.scala
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,11 @@ 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) {
1603-
if (probe.isTrait) ConstrArgsInParentWhichIsTraitError(encodedtpt, probe)
1604-
else () // a class in a mixin position - this warrants an error in `validateParentClasses`
1602+
if (probe.isTrait && inMixinPosition && !argss.isEmpty)
1603+
ConstrArgsInParentWhichIsTraitError(encodedtpt, probe)
1604+
// 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
16061606
// matches the # of ctor parameters or stuff like that
1607-
}
16081607
typedType(decodedtpt)
16091608
} else {
16101609
val supertpt = typedTypeConstructor(decodedtpt)
@@ -1757,8 +1756,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
17571756
case Nil => List(atPos(templ.pos)(TypeTree(AnyRefTpe)))
17581757
case first :: rest =>
17591758
try {
1759+
val firstMixin = !context.owner.isAnonymousClass // permit new T() {} syntax
17601760
val supertpts = fixDuplicateSyntheticParents(normalizeFirstParent(
1761-
typedParentType(first, templ, inMixinPosition = false) +:
1761+
typedParentType(first, templ, inMixinPosition = firstMixin) +:
17621762
(rest map (typedParentType(_, templ, inMixinPosition = true)))))
17631763

17641764
// if that is required to infer the targs of a super call

‎test/files/neg/t6805.check

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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:11: error: trait T is abstract; cannot be instantiated
8+
def u: T = new T() // error
9+
^
10+
t6805.scala:12: error: trait T is a trait; does not take constructor arguments
11+
def v: T = new X with T() // error
12+
^
13+
4 errors

‎test/files/neg/t6805.scala

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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() {} // no error, permissive for Java anon syntax, just because
11+
def u: T = new T() // error
12+
def v: T = new X with T() // error
13+
def w: T = new T {}
14+
}

‎test/files/pos/t6666d.scala

Copy file name to clipboardExpand all lines: test/files/pos/t6666d.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.math.Ordering
44

55
class Test[K](param:TreeMap[K,Int]){
66
def this() = this({
7-
implicit object TreeOrd extends Ordering[K](){
7+
implicit val TreeOrd: Ordering[K] = new Ordering[K] {
88
def compare(a: K, b: K) = {
99
-1
1010
}

‎test/tasty/run/src-2/tastytest/TestGreeting.scala

Copy file name to clipboardExpand all lines: test/tasty/run/src-2/tastytest/TestGreeting.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object TestGreeting extends Suite("TestGreeting") {
66
final val greeting = "Hello, World!"
77
}
88

9-
test(assert(new Greeter with Hello().accessGreeting === "Hello, World!"))
9+
test(assert((new Greeter with Hello).accessGreeting === "Hello, World!"))
1010

1111
}

‎test/tasty/run/src-2/tastytest/TestInner.scala

Copy file name to clipboardExpand all lines: test/tasty/run/src-2/tastytest/TestInner.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package tastytest
33
object TestInner extends Suite("TestInner") {
44

55
test(assert(Inner.Foo.Bar != null))
6-
test(assert(new Inner.Foo(){}.isInstanceOf[Inner.Foo]))
6+
test(assert(new Inner.Foo {}.isInstanceOf[Inner.Foo]))
77

88
}

‎test/tasty/run/src-2/tastytest/TestReader.scala

Copy file name to clipboardExpand all lines: test/tasty/run/src-2/tastytest/TestReader.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package tastytest
22

33
object TestReader extends Suite("TestReader") {
44

5-
implicit def mkReaderMonad[Ctx]: Reader[Ctx] = new Reader[Ctx]() {}
5+
implicit def mkReaderMonad[Ctx]: Reader[Ctx] = new Reader[Ctx] {}
66

77
def pureToString[F[_], A](fa: F[A])(implicit F: Monad[F]): F[String] =
88
F.flatMap(fa)(a => F.pure(a.toString))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.