Skip to content

Commit a88b76a

Browse files
committed
Consider superclass context
Filter member of refinement, handle Annotated TypeTree is usage of simple name Handle quotes and splices Tighten allowance for serialization methods Restore inferred type is not a usage, noprefix is in import Warn for top level private Import given takes NoPrefix usage Don't ignore params of public methods Accept updated semanticdb output
1 parent 751348a commit a88b76a

25 files changed

+579
-108
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class Compiler {
4848
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
4949
List(new Inlining) :: // Inline and execute macros
5050
List(new PostInlining) :: // Add mirror support for inlined code
51-
List(new CheckUnused.PostInlining) :: // Check for unused elements
5251
List(new Staging) :: // Check staging levels and heal staged types
5352
List(new Splicing) :: // Replace level 1 splices with holes
5453
List(new PickleQuotes) :: // Turn quoted trees into explicit run-time data structures
54+
List(new CheckUnused.PostInlining) :: // Check for unused elements
5555
Nil
5656

5757
/** Phases dealing with the transformation from pickled trees to backend trees */

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ class Definitions {
494494
@tu lazy val Predef_undefined: Symbol = ScalaPredefModule.requiredMethod(nme.???)
495495
@tu lazy val ScalaPredefModuleClass: ClassSymbol = ScalaPredefModule.moduleClass.asClass
496496

497+
@tu lazy val SameTypeClass: ClassSymbol = requiredClass("scala.=:=")
498+
@tu lazy val SameType_refl: Symbol = SameTypeClass.companionModule.requiredMethod(nme.refl)
497499
@tu lazy val SubTypeClass: ClassSymbol = requiredClass("scala.<:<")
498500
@tu lazy val SubType_refl: Symbol = SubTypeClass.companionModule.requiredMethod(nme.refl)
499501

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 104 additions & 56 deletions
Large diffs are not rendered by default.

tests/pos/i17631.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Xfatal-warnings -Wunused:all -deprecation -feature
1+
//> using options -Werror -Wunused:all -deprecation -feature
22

33
object foo {
44
type Bar
@@ -32,3 +32,23 @@ object Main {
3232
(bad1, bad2)
3333
}
3434
}
35+
36+
def `i18388`: Unit =
37+
def func(pred: [A] => A => Boolean): Unit =
38+
val _ = pred
39+
()
40+
val _ = func
41+
42+
trait L[T]:
43+
type E
44+
45+
def `i19748` =
46+
type Warn1 = [T] => (l: L[T]) => T => l.E
47+
type Warn2 = [T] => L[T] => T
48+
type Warn3 = [T] => T => T
49+
def use(x: (Warn1, Warn2, Warn3)) = x
50+
use
51+
52+
type NoWarning1 = [T] => (l: L[T]) => T => l.E
53+
type NoWarning2 = [T] => L[T] => T
54+
type NoWarning3 = [T] => T => T

tests/pos/i18366.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
//> using options -Xfatal-warnings -Wunused:all
1+
//> using options -Werror -Wunused:all
22

33
trait Builder {
44
def foo(): Unit
55
}
66

7-
def repro =
7+
def `i18366` =
88
val builder: Builder = ???
99
import builder.{foo => bar}
10-
bar()
10+
bar()
11+
12+
import java.io.DataOutputStream
13+
14+
val buffer: DataOutputStream = ???
15+
16+
import buffer.{write => put}
17+
18+
def `i17315` =
19+
put(0: Byte)

tests/semanticdb/metac.expect

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ Text => empty
575575
Language => Scala
576576
Symbols => 108 entries
577577
Occurrences => 127 entries
578-
Diagnostics => 6 entries
578+
Diagnostics => 10 entries
579579
Synthetics => 2 entries
580580

581581
Symbols:
@@ -830,6 +830,10 @@ See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifie
830830
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
831831
[22:27..22:28): [warning] unused explicit parameter
832832
[24:10..24:11): [warning] unused explicit parameter
833+
[36:11..36:12): [warning] unused explicit parameter
834+
[39:11..39:12): [warning] unused explicit parameter
835+
[39:19..39:20): [warning] unused explicit parameter
836+
[51:30..51:31): [warning] unused explicit parameter
833837

834838
Synthetics:
835839
[51:16..51:27):List(1).map => *[Int]
@@ -3533,6 +3537,7 @@ Text => empty
35333537
Language => Scala
35343538
Symbols => 62 entries
35353539
Occurrences => 165 entries
3540+
Diagnostics => 2 entries
35363541
Synthetics => 39 entries
35373542

35383543
Symbols:
@@ -3766,6 +3771,10 @@ Occurrences:
37663771
[68:18..68:24): impure -> local20
37673772
[68:30..68:31): s -> local16
37683773

3774+
Diagnostics:
3775+
[19:21..19:22): [warning] unused explicit parameter
3776+
[41:4..41:5): [warning] unused explicit parameter
3777+
37693778
Synthetics:
37703779
[5:2..5:13):List(1).map => *[Int]
37713780
[5:2..5:6):List => *.apply[Int]
@@ -4235,6 +4244,7 @@ Text => empty
42354244
Language => Scala
42364245
Symbols => 6 entries
42374246
Occurrences => 11 entries
4247+
Diagnostics => 2 entries
42384248

42394249
Symbols:
42404250
example/Vararg# => class Vararg extends Object { self: Vararg => +3 decls }
@@ -4257,6 +4267,10 @@ Occurrences:
42574267
[4:18..4:21): Int -> scala/Int#
42584268
[4:26..4:30): Unit -> scala/Unit#
42594269

4270+
Diagnostics:
4271+
[3:11..3:12): [warning] unused explicit parameter
4272+
[4:11..4:12): [warning] unused explicit parameter
4273+
42604274
expect/dep-match.scala
42614275
----------------------
42624276

@@ -4873,6 +4887,7 @@ Text => empty
48734887
Language => Scala
48744888
Symbols => 36 entries
48754889
Occurrences => 48 entries
4890+
Diagnostics => 5 entries
48764891

48774892
Symbols:
48784893
local0 => type N$1 <: Nat
@@ -4962,6 +4977,13 @@ Occurrences:
49624977
[23:35..23:39): Zero -> recursion/Nats.Zero.
49634978
[23:40..23:42): ++ -> recursion/Nats.Nat#`++`().
49644979

4980+
Diagnostics:
4981+
[10:24..10:24): [warning] unused local definition
4982+
[10:33..11:5): [warning] unused local definition
4983+
[23:19..23:19): [warning] unused local definition
4984+
[23:24..23:32): [warning] unused local definition
4985+
[23:40..25:2): [warning] unused local definition
4986+
49654987
expect/semanticdb-Definitions.scala
49664988
-----------------------------------
49674989

@@ -5006,7 +5028,7 @@ Text => empty
50065028
Language => Scala
50075029
Symbols => 50 entries
50085030
Occurrences => 78 entries
5009-
Diagnostics => 4 entries
5031+
Diagnostics => 5 entries
50105032
Synthetics => 2 entries
50115033

50125034
Symbols:
@@ -5142,6 +5164,7 @@ Occurrences:
51425164
[25:33..25:36): ??? -> scala/Predef.`???`().
51435165

51445166
Diagnostics:
5167+
[5:19..5:20): [warning] unused private member
51455168
[9:30..9:31): [warning] unused explicit parameter
51465169
[9:36..9:37): [warning] unused explicit parameter
51475170
[9:42..9:43): [warning] unused explicit parameter
@@ -5161,7 +5184,7 @@ Text => empty
51615184
Language => Scala
51625185
Symbols => 143 entries
51635186
Occurrences => 246 entries
5164-
Diagnostics => 4 entries
5187+
Diagnostics => 5 entries
51655188
Synthetics => 1 entries
51665189

51675190
Symbols:
@@ -5565,6 +5588,7 @@ This construct can be rewritten automatically under -rewrite -source 3.4-migrati
55655588
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
55665589
[71:31..71:31): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
55675590
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
5591+
[96:13..96:14): [warning] unused explicit parameter
55685592

55695593
Synthetics:
55705594
[68:20..68:24):@ann => *[Int]

tests/warn/i15503a.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ package testImportsInImports:
213213
package c:
214214
import a.b // OK
215215
import b.x // OK
216-
val y = x
216+
import b.x as z // OK
217+
val y = x + z
217218

218219
//-------------------------------------
219220
package testOnOverloadedMethodsImports:
@@ -265,4 +266,4 @@ package foo.test.typeapply.hklamdba.i16680:
265266
import foo.IO // OK
266267

267268
def f[F[_]]: String = "hello"
268-
def go = f[IO]
269+
def go = f[IO]

tests/warn/i15503b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ package foo.scala2.tests:
117117

118118
object Types {
119119
def l1() = {
120-
object HiObject { def f = this } // OK
120+
object HiObject { def f = this } // warn
121121
class Hi { // warn
122122
def f1: Hi = new Hi
123123
def f2(x: Hi) = x
@@ -141,4 +141,4 @@ package test.foo.twisted.i16682:
141141
}
142142
isInt
143143

144-
def f = myPackage("42")
144+
def f = myPackage("42")

tests/warn/i15503e.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -Wunused:explicits
1+
//> using options -Wunused:explicits
22

33
object Foo {
44
/* This goes around the "trivial method" detection */
@@ -31,7 +31,7 @@ package scala3main:
3131
package foo.test.lambda.param:
3232
val default_val = 1
3333
val a = (i: Int) => i // OK
34-
val b = (i: Int) => default_val // OK
34+
val b = (i: Int) => default_val // warn
3535
val c = (_: Int) => default_val // OK
3636

3737
package foo.test.trivial:
@@ -64,7 +64,7 @@ package foo.test.i16865:
6464
trait Bar extends Foo
6565

6666
object Ex extends Bar:
67-
def fn(a: Int, b: Int): Int = b + 3 // OK
67+
def fn(a: Int, b: Int): Int = b + 3 // warn
6868

6969
object Ex2 extends Bar:
70-
override def fn(a: Int, b: Int): Int = b + 3 // OK
70+
override def fn(a: Int, b: Int): Int = b + 3 // warn

tests/warn/i15503f.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ val default_int = 1
66
object Xd {
77
private def f1(a: Int) = a // OK
88
private def f2(a: Int) = 1 // OK
9-
private def f3(a: Int)(using Int) = a // OK
10-
private def f4(a: Int)(using Int) = default_int // OK
9+
private def f3(a: Int)(using Int) = a // warn
10+
private def f4(a: Int)(using Int) = default_int // warn
1111
private def f6(a: Int)(using Int) = summon[Int] // OK
1212
private def f7(a: Int)(using Int) = summon[Int] + a // OK
1313
private def f8(a: Int)(using foo: Int) = a // warn

0 commit comments

Comments
 (0)