Skip to content

Commit 6d0af1a

Browse files
committed
Fix scala#8276: Do not infer types of default argument getters
1 parent eb34c6c commit 6d0af1a

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ object desugar {
263263
name = DefaultGetterName(methName, n),
264264
tparams = meth.tparams.map(tparam => dropContextBounds(toDefParam(tparam, keepAnnotations = true))),
265265
vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam(_, keepAnnotations = true, keepDefault = false)), n),
266-
tpt = TypeTree(),
266+
tpt = vparam.tpt,
267267
rhs = vparam.rhs
268268
)
269269
.withMods(Modifiers(mods.flags & (AccessFlags | Synthetic), mods.privateWithin))

tests/neg/i4659b.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/neg/variances-b.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Tests variance checking on default methods
2+
import reflect.ClassTag
3+
4+
class Foo[+A: ClassTag](x: A) {
5+
6+
private[this] val elems: Array[A] = Array(x)
7+
8+
def f[B](x: Array[B] = elems): Array[B] = x // error: Found: (Foo.this.elems : Array[A]) Required: Array[B]
9+
10+
}

tests/neg/variances.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Foo[+A: ClassTag](x: A) {
55

66
private[this] val elems: Array[A] = Array(x)
77

8-
def f[B](x: Array[B] = elems): Array[B] = x // error (1) should give a variance error here or ...
8+
def f[B](x: Array[B] = ???): Array[B] = x
99

1010
}
1111

tests/pos/i8276.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object NOTHING
2+
3+
inline given [A] as Conversion[NOTHING.type, Option[A]] = _ => None
4+
5+
def apply[A](p: Vector[A], o: Option[A] = NOTHING): Unit = ???
6+
7+
apply[String](Vector.empty)

tests/run/i4659b.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
case class SourcePosition(outer: SourcePosition = (NoSourcePosition: SourcePosition))
1+
case class SourcePosition(outer: SourcePosition = NoSourcePosition) {
2+
// TODO: outer is null because it was not initialized in the consturctor of NoSourcePosition
3+
// This is a task for the initalization checker
4+
// assert(outer != null)
5+
}
26

3-
// The code should not compile -- currently out of reach
47
object NoSourcePosition extends SourcePosition()
58

6-
object Test extends App {
7-
assert(NoSourcePosition.outer == null)
8-
}
9+
@main def Test = NoSourcePosition

0 commit comments

Comments
 (0)