File tree 2 files changed +36
-3
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings
2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import dotty.tools.dotc.core.Annotations
26
26
import dotty .tools .dotc .core .Definitions
27
27
import dotty .tools .dotc .core .Types .ConstantType
28
28
import dotty .tools .dotc .core .NameKinds .WildcardParamName
29
+ import dotty .tools .dotc .core .Types .TermRef
29
30
30
31
31
32
@@ -569,7 +570,13 @@ object CheckUnused:
569
570
defdef.symbol.is(Deferred ) ||
570
571
(rhs match {
571
572
case _ : tpd.Literal => true
572
- case _ => rhs.tpe.isInstanceOf [ConstantType ]
573
+ case _ => rhs.tpe match
574
+ case ConstantType (_) => true
575
+ case tp : TermRef =>
576
+ // Detect Scala 2 SingleType
577
+ tp.underlying.classSymbol.is(Flags .Module )
578
+ case _ =>
579
+ false
573
580
})
574
581
def registerTrivial (using Context ): Unit =
575
582
if defdef.isTrivial then
@@ -590,7 +597,6 @@ object CheckUnused:
590
597
private def isWildcard : Boolean =
591
598
thisName == StdNames .nme.WILDCARD || thisName.is(WildcardParamName )
592
599
593
-
594
600
end UnusedData
595
601
596
602
private object UnusedData :
Original file line number Diff line number Diff line change @@ -24,4 +24,31 @@ package scala2main:
24
24
package scala3main:
25
25
/* This goes around the "trivial method" detection */
26
26
val default_unit = ()
27
- @ main def hello = println(" Hello World" ) // OK
27
+ @ main def hello = println(" Hello World" ) // OK
28
+
29
+ package foo .test .lambda .param:
30
+ val default_val = 1
31
+ val a = (i : Int ) => i // OK
32
+ val b = (i : Int ) => default_val // error
33
+ val c = (_ : Int ) => default_val // OK
34
+
35
+ package foo .test .trivial:
36
+ /* A twisted test from Scala 2 */
37
+ class C {
38
+ def answer : 42 = 42
39
+ object X
40
+ def g0 (x : Int ) = ??? // OK
41
+ def f0 (x : Int ) = () // OK
42
+ def f1 (x : Int ) = throw new RuntimeException // OK
43
+ def f2 (x : Int ) = 42 // OK
44
+ def f3 (x : Int ): Option [Int ] = None // OK
45
+ def f4 (x : Int ) = classOf [Int ] // OK
46
+ def f5 (x : Int ) = answer + 27 // OK
47
+ def f6 (x : Int ) = X // OK
48
+ def f7 (x : Int ) = Y // OK
49
+ def f8 (x : Int ): List [C ] = Nil // OK
50
+ def f9 (x : Int ): List [Int ] = List (1 ,2 ,3 ,4 ) // error
51
+ def foo : Int = 32 // OK
52
+ def f77 (x : Int ) = foo // error
53
+ }
54
+ object Y
You can’t perform that action at this time.
0 commit comments