Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit41aafb7

Browse files
committed
Check trivial trait args
1 parent8f9df67 commit41aafb7

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

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

Lines 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
defcookIfNeeded(tpt:Tree)=if (context.unit.isJava) tpt modifyType rawToExistentialelse 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
valsupertpt= typedTypeConstructor(decodedtpt)
@@ -1757,8 +1756,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
17571756
caseNil=>List(atPos(templ.pos)(TypeTree(AnyRefTpe)))
17581757
case first:: rest=>
17591758
try {
1759+
valfirstMixin=!context.owner.isAnonymousClass// permit new T() {} syntax
17601760
valsupertpts= 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

Lines 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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
traitT
3+
4+
classCextendsT()// error
5+
6+
classX
7+
classYextendsXwithT()// error
8+
9+
objectfuncs {
10+
deft:T=newT() {}// no error, permissive for Java anon syntax, just because
11+
defu:T=newT()// error
12+
defv:T=newXwithT()// error
13+
defw:T=newT {}
14+
}

‎test/files/pos/t6666d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.math.Ordering
44

55
classTest[K](param:TreeMap[K,Int]){
66
defthis()=this({
7-
implicitobjectTreeOrdextendsOrdering[K](){
7+
implicitvalTreeOrd:Ordering[K]=newOrdering[K]{
88
defcompare(a:K,b:K)= {
99
-1
1010
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object TestGreeting extends Suite("TestGreeting") {
66
finalvalgreeting="Hello, World!"
77
}
88

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

1111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package tastytest
33
objectTestInnerextendsSuite("TestInner") {
44

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

88
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package tastytest
22

33
objectTestReaderextendsSuite("TestReader") {
44

5-
implicitdefmkReaderMonad[Ctx]:Reader[Ctx]=newReader[Ctx]() {}
5+
implicitdefmkReaderMonad[Ctx]:Reader[Ctx]=newReader[Ctx] {}
66

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp