Skip to content

Commit be17ad1

Browse files
authored
Mark the type of lifted definitions as inferred (#24104)
Fix #24100 #24101 #24102 The capture set from lifted arguments was not removed correctly. * Mark the type of lifted definitions as inferred * Don't make overriding types declared when cc is not enabled
2 parents b7cae74 + 2818382 commit be17ad1

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
371371
* clean retains annotations from such types. But for an overriding symbol the
372372
* retains annotations come from the explicitly declared parent types, so should
373373
* be kept.
374+
* TODO: If the overriden type is an InferredType, we should probably clean retains
375+
* from both types as well.
374376
*/
375377
private def makeOverrideTypeDeclared(symbol: Symbol, tpt: Tree)(using Context): Tree =
376378
tpt match
377379
case tpt: InferredTypeTree
378-
if symbol.allOverriddenSymbols.hasNext =>
380+
if Feature.ccEnabled && symbol.allOverriddenSymbols.hasNext =>
379381
TypeTree(tpt.tpe, inferred = false).withSpan(tpt.span).withAttachmentsFrom(tpt)
380382
case _ =>
381383
tpt

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ abstract class Lifter {
3737
protected def liftedFlags: FlagSet = EmptyFlags
3838

3939
/** The tree of a lifted definition */
40-
protected def liftedDef(sym: TermSymbol, rhs: Tree)(using Context): MemberDef = ValDef(sym, rhs)
40+
protected def liftedDef(sym: TermSymbol, rhs: Tree)(using Context): MemberDef =
41+
// Mark the type of lifted definitions as inferred
42+
ValDef(sym, rhs, inferred = true)
4143

4244
private def lift(defs: mutable.ListBuffer[Tree], expr: Tree, prefix: TermName = EmptyTermName)(using Context): Tree =
4345
if (noLift(expr)) expr
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import language.experimental.captureChecking
2+
3+
trait MyMap[K, V]:
4+
def filterNot(pred: ((K, V)) => Boolean): MyMap[K, V]^{this, pred} = ???
5+
6+
trait MySeq[+T]:
7+
def map[U](f: T => U): MySeq[U]^{this, f} = ???
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// i24101
2+
3+
trait AttributeValue
4+
5+
case class CompletedSpan(
6+
name: String, // remove to make it compile
7+
attributes: MyMap[String, AttributeValue],
8+
){
9+
lazy val allAttributes: MyMap[String, AttributeValue] = attributes
10+
var allAttributes2: MyMap[String, AttributeValue] = attributes
11+
}
12+
13+
def Test =
14+
val span: CompletedSpan = ???
15+
span.copy(attributes = span.allAttributes.filterNot { _ => false })
16+
span.copy(attributes = span.allAttributes2.filterNot { _ => false })
17+
18+
// i24100
19+
20+
trait Type
21+
22+
type ColumnDef = ColumnDef_[Type]
23+
case class ColumnDef_[+T](comments: String)
24+
25+
type TableDef = TableDef_[ColumnDef]
26+
case class TableDef_[+C <: ColumnDef_[?]](cols: MySeq[C])
27+
28+
abstract class DdlGenerator:
29+
// The result type is inferred here
30+
def columnComments(t: TableDef) = t.cols.map(_ => "")
31+
32+
class CassandraDdlGenerator() extends DdlGenerator:
33+
// The result type should be inferred here as well
34+
override def columnComments(t: TableDef) = ???

0 commit comments

Comments
 (0)