Skip to content

Commit db11bb7

Browse files
committed
Don't complain about non-conforming inferred types in empty package
We now assume that all members of the empty package are meant to be used alone or in projects without separate compilation. So the warning that an inferred type does not conform to a type seen in separate compilation is dropped because it was a hassle for experimentation.
1 parent 5b9f13b commit db11bb7

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,10 @@ class CheckCaptures extends Recheck, SymTransformer:
10591059

10601060
def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
10611061
sym.isLocalToCompilationUnit // Symbols that can't be seen outside the compilation unit can always have inferred types
1062-
|| sym.privateWithin == defn.EmptyPackageClass
1063-
// We make an exception for private symbols in a toplevel file in the empty package
1062+
|| ctx.owner.enclosingPackageClass.isEmptyPackage
1063+
// We make an exception for symbols in the empty package.
10641064
// these could theoretically be accessed from other files in the empty package, but
1065-
// it would be too annoying to require explicit types.
1065+
// usually it would be too annoying to require explicit types.
10661066
|| sym.name.is(DefaultGetterName) // Default getters are exempted since otherwise it would be
10671067
// too annoying. This is a hole since a defualt getter's result type
10681068
// might leak into a type variable.
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:4:13 ----------------------------------------
2-
4 | val x = Foo(m) // error
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:5:13 ----------------------------------------
2+
5 | val x = Foo(m) // error
33
| ^^^^^^
4-
| Found: Foo{val m: (Bar.this.m² : STR^)}^{Bar.this.m²}
5-
| Required: Foo
4+
| Found: test.Foo{val m: (Bar.this.m² : test.STR^)}^{Bar.this.m²}
5+
| Required: test.Foo
66
|
77
| where: ^ refers to a fresh root capability in the type of value m²
88
| m is a value in class Foo
99
| m² is a value in class Bar
1010
|
1111
|
12-
| Note that the expected type Foo
12+
| Note that the expected type test.Foo
1313
| is the previously inferred type of value x
1414
| which is also the type seen in separately compiled sources.
15-
| The new inferred type Foo{val m: (Bar.this.m : STR^)}^{Bar.this.m}
15+
| The new inferred type test.Foo{val m: (Bar.this.m : test.STR^)}^{Bar.this.m}
1616
| must conform to this type.
1717
|
1818
| longer explanation available when compiling with `-explain`
19-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:6:13 ----------------------------------------
20-
6 | val x = Foo(m) // error
19+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:7:13 ----------------------------------------
20+
7 | val x = Foo(m) // error
2121
| ^^^^^^
22-
| Found: Foo{val m: (Baz.this.m² : STR^)}^{Baz.this.m²}
23-
| Required: Foo
22+
| Found: test.Foo{val m: (Baz.this.m² : test.STR^)}^{Baz.this.m²}
23+
| Required: test.Foo
2424
|
2525
| where: ^ refers to a fresh root capability in the type of value m²
2626
| m is a value in class Foo
2727
| m² is a value in trait Baz
2828
|
2929
|
30-
| Note that the expected type Foo
30+
| Note that the expected type test.Foo
3131
| is the previously inferred type of value x
3232
| which is also the type seen in separately compiled sources.
33-
| The new inferred type Foo{val m: (Baz.this.m : STR^)}^{Baz.this.m}
33+
| The new inferred type test.Foo{val m: (Baz.this.m : test.STR^)}^{Baz.this.m}
3434
| must conform to this type.
3535
|
3636
| longer explanation available when compiling with `-explain`
37-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:8:13 ----------------------------------------
38-
8 | val x = Foo(m) // error
37+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:9:13 ----------------------------------------
38+
9 | val x = Foo(m) // error
3939
| ^^^^^^
40-
| Found: Foo{val m: (Bar1.this.m² : STR^)}^{Bar1.this.m²}
41-
| Required: Foo
40+
| Found: test.Foo{val m: (Bar1.this.m² : test.STR^)}^{Bar1.this.m²}
41+
| Required: test.Foo
4242
|
4343
| where: ^ refers to a fresh root capability in the type of value m²
4444
| m is a value in class Foo
4545
| m² is a value in class Bar1
4646
|
4747
|
48-
| Note that the expected type Foo
48+
| Note that the expected type test.Foo
4949
| is the previously inferred type of value x
5050
| which is also the type seen in separately compiled sources.
51-
| The new inferred type Foo{val m: (Bar1.this.m : STR^)}^{Bar1.this.m}
51+
| The new inferred type test.Foo{val m: (Bar1.this.m : test.STR^)}^{Bar1.this.m}
5252
| must conform to this type.
5353
|
5454
| longer explanation available when compiling with `-explain`
55-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:10:13 ---------------------------------------
56-
10 | val x = Foo(m) // error
55+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:11:13 ---------------------------------------
56+
11 | val x = Foo(m) // error
5757
| ^^^^^^
58-
| Found: Foo{val m: (Baz2.this.m² : STR^)}^{Baz2.this.m²}
59-
| Required: Foo
58+
| Found: test.Foo{val m: (Baz2.this.m² : test.STR^)}^{Baz2.this.m²}
59+
| Required: test.Foo
6060
|
6161
| where: ^ refers to a fresh root capability in the type of value m²
6262
| m is a value in class Foo
6363
| m² is a value in trait Baz2
6464
|
6565
|
66-
| Note that the expected type Foo
66+
| Note that the expected type test.Foo
6767
| is the previously inferred type of value x
6868
| which is also the type seen in separately compiled sources.
69-
| The new inferred type Foo{val m: (Baz2.this.m : STR^)}^{Baz2.this.m}
69+
| The new inferred type test.Foo{val m: (Baz2.this.m : test.STR^)}^{Baz2.this.m}
7070
| must conform to this type.
7171
|
7272
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/i15116.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package test
12
class STR
23
class Foo(m: STR^)
34
class Bar(val m: STR^):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class C
2+
3+
def t =
4+
val x: C^ = C()
5+
x

0 commit comments

Comments
 (0)