Skip to content

Commit a24915c

Browse files
committed
Don't check bounds for type definitions in abstract classes
Don't check bounds for type definitions in abstract classes, traits, or refinements. Bounds violations will be detected when values of these types are created.
1 parent cac3d78 commit a24915c

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
399399
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
400400
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
401401
else
402-
if !sym.is(Param) then
402+
if !sym.is(Param) && !sym.owner.isOneOf(AbstractOrTrait) then
403403
Checking.checkGoodBounds(tree.symbol)
404404
(tree.rhs, sym.info) match
405405
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>

tests/neg/i11572.scala renamed to tests/init/neg/i11572.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class A {
55
trait Bounded {
66
type T >: Cov[Int] <: Cov[String] // error
77
}
8-
val t: Bounded = new Bounded {
8+
val t: Bounded = new Bounded { // error
99
// Note: using this instead of t produces an error (as expected)
1010
override type T >: t.T <: t.T
1111
}
File renamed without changes.

tests/neg-strict/i1050.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object Indirect {
100100
trait U {
101101
trait X {
102102
val q: A & B = ???
103-
type M = q.L // error: conflicting bounds
103+
type M = q.L
104104
}
105105
final lazy val p: X = ???
106106
def brand(x: Any): p.M = x // error: conflicting bounds
@@ -119,7 +119,7 @@ object Indirect2 {
119119
}
120120
trait X {
121121
val q: Y = ???
122-
type M = q.r.L // error: conflicting bounds
122+
type M = q.r.L
123123
}
124124
final lazy val p: X = ???
125125
def brand(x: Any): p.M = x // error: conflicting bounds
@@ -152,7 +152,7 @@ object Rec2 {
152152
}
153153
trait X {
154154
val q: Y = ???
155-
type M = q.r.L // error: conflicting bounds
155+
type M = q.r.L
156156
}
157157
final lazy val p: X = ???
158158
def brand(x: Any): p.M = x // error: conflicting bounds
@@ -171,7 +171,7 @@ object Indirect3 {
171171
}
172172
trait X {
173173
val q: Y = ???
174-
type M = q.r.L // error: conflicting bounds
174+
type M = q.r.L
175175
}
176176
final lazy val p: X = ???
177177
def brand(x: Any): p.M = x // error: conflicting bounds
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package i5854
22

33
class B/*<-i5854::B#*/ {
4-
// Known issue: Can't lookup the symbol of `b.A`
5-
// we have to register the symbol of `b { type A }` to the refinementSymtab first
6-
// then resolve, or assign same semanticdb symbol for both
7-
// fake symbol for b.A, and real symbol of A in b
84
val a/*<-i5854::B#a.*/: String/*->scala::Predef.String#*/ = (((1: Any/*->scala::Any#*/): b/*->i5854::B#b.*/.A): Nothing/*->scala::Nothing#*/): String/*->scala::Predef.String#*/
9-
val b/*<-i5854::B#b.*/: { type A/*<-local0*/ >: Any/*->scala::Any#*/ <: Nothing/*->scala::Nothing#*/ } = loop/*->i5854::B#loop().*/() // error
5+
val b/*<-i5854::B#b.*/: { type A/*<-local0*/ >: Any/*->scala::Any#*/ <: Nothing/*->scala::Nothing#*/ } = loop/*->i5854::B#loop().*/() // error
106
def loop/*<-i5854::B#loop().*/(): Nothing/*->scala::Nothing#*/ = loop/*->i5854::B#loop().*/()
117
}

tests/semanticdb/expect/i5854.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package i5854
2+
3+
class B {
4+
val a: String = (((1: Any): b.A): Nothing): String
5+
val b: { type A >: Any <: Nothing } = loop() // error
6+
def loop(): Nothing = loop()
7+
}

tests/semanticdb/metac.expect

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,6 +3923,43 @@ Occurrences:
39233923
[0:8..0:15): example <- example/
39243924
[2:6..2:24): FilenameWithSpaces <- example/FilenameWithSpaces#
39253925

3926+
expect/i5854.scala
3927+
------------------
3928+
3929+
Summary:
3930+
Schema => SemanticDB v4
3931+
Uri => i5854.scala
3932+
Text => empty
3933+
Language => Scala
3934+
Symbols => 6 entries
3935+
Occurrences => 16 entries
3936+
3937+
Symbols:
3938+
i5854/B# => class B extends Object { self: B => +4 decls }
3939+
i5854/B#`<init>`(). => primary ctor <init> (): B
3940+
i5854/B#a. => val method a String
3941+
i5854/B#b. => val method b Object { type A >: Any <: Nothing }
3942+
i5854/B#loop(). => method loop (): Nothing
3943+
local0 => type A >: Any <: Nothing
3944+
3945+
Occurrences:
3946+
[0:8..0:13): i5854 <- i5854/
3947+
[2:6..2:7): B <- i5854/B#
3948+
[3:6..3:7): a <- i5854/B#a.
3949+
[3:9..3:15): String -> scala/Predef.String#
3950+
[3:24..3:27): Any -> scala/Any#
3951+
[3:30..3:31): b -> i5854/B#b.
3952+
[3:36..3:43): Nothing -> scala/Nothing#
3953+
[3:46..3:52): String -> scala/Predef.String#
3954+
[4:6..4:7): b <- i5854/B#b.
3955+
[4:16..4:17): A <- local0
3956+
[4:21..4:24): Any -> scala/Any#
3957+
[4:28..4:35): Nothing -> scala/Nothing#
3958+
[4:40..4:44): loop -> i5854/B#loop().
3959+
[5:6..5:10): loop <- i5854/B#loop().
3960+
[5:14..5:21): Nothing -> scala/Nothing#
3961+
[5:24..5:28): loop -> i5854/B#loop().
3962+
39263963
expect/i9727.scala
39273964
------------------
39283965

0 commit comments

Comments
 (0)