Skip to content

Commit 9067e86

Browse files
committed
A fix and a partially failing test
1 parent 0f4aba8 commit 9067e86

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ object NamerOps:
1414
* @param ctor the constructor
1515
*/
1616
def effectiveResultType(ctor: Symbol, paramss: List[List[Symbol]])(using Context): Type =
17-
paramss match
17+
var resType = paramss match
1818
case TypeSymbols(tparams) :: _ =>
19-
var resType = ctor.owner.typeRef.appliedTo(tparams.map(_.typeRef))
20-
for params <- paramss; param <- params do
21-
if param.is(Tracked) then
22-
resType = RefinedType(resType, param.name, param.termRef)
23-
resType
24-
case _ => ctor.owner.typeRef
19+
ctor.owner.typeRef.appliedTo(tparams.map(_.typeRef))
20+
case _ =>
21+
ctor.owner.typeRef
22+
for params <- paramss; param <- params do
23+
if param.is(Tracked) then
24+
resType = RefinedType(resType, param.name, param.termRef)
25+
resType
2526

2627
/** If isConstructor, make sure it has at least one non-implicit parameter list
2728
* This is done by adding a () in front of a leading old style implicit parameter,

tests/neg/i3964.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
trait Animal
2+
class Dog extends Animal
3+
class Cat extends Animal
4+
5+
object Test1:
6+
7+
abstract class Bar { val x: Animal }
8+
val bar: Bar { val x: Cat } = new Bar { val x = new Cat } // error, but should work
9+
10+
trait Foo { val x: Animal }
11+
val foo: Foo { val x: Cat } = new Foo { val x = new Cat } // error, but should work
12+
13+
object Test2:
14+
abstract class Bar(tracked val x: Animal)
15+
val b = new Bar(new Cat)
16+
val bar: Bar { val x: Cat } = new Bar(new Cat) // ok
17+
18+
trait Foo(tracked val x: Animal)
19+
val foo: Foo { val x: Cat } = new Foo(new Cat) // ok
20+
21+
object Test3:
22+
trait Vec(tracked val size: Int)
23+
class Vec8 extends Vec(8)
24+
25+
abstract class Lst(tracked val size: Int)
26+
class Lst8 extends Lst(8)
27+
28+
val v8a: Vec { val size: 8 } = new Vec8 // error, but should work
29+
val v8b: Vec { val size: 8 } = new Vec(8) // ok
30+
31+
val l8a: Lst { val size: 8 } = new Lst8 // error, but should work
32+
val l8b: Lst { val size: 8 } = new Lst(8) // ok

0 commit comments

Comments
 (0)