@@ -437,13 +437,13 @@ object desugar {
437
437
private def toDefParam (tparam : TypeDef , keepAnnotations : Boolean ): TypeDef = {
438
438
var mods = tparam.rawMods
439
439
if (! keepAnnotations) mods = mods.withAnnotations(Nil )
440
- tparam.withMods(mods & ( EmptyFlags | Sealed ) | Param )
440
+ tparam.withMods(mods & EmptyFlags | Param )
441
441
}
442
442
private def toDefParam (vparam : ValDef , keepAnnotations : Boolean , keepDefault : Boolean ): ValDef = {
443
443
var mods = vparam.rawMods
444
444
if (! keepAnnotations) mods = mods.withAnnotations(Nil )
445
445
val hasDefault = if keepDefault then HasDefault else EmptyFlags
446
- vparam.withMods(mods & (GivenOrImplicit | Erased | hasDefault) | Param )
446
+ vparam.withMods(mods & (GivenOrImplicit | Erased | hasDefault | Tracked ) | Param )
447
447
}
448
448
449
449
def mkApply (fn : Tree , paramss : List [ParamClause ])(using Context ): Tree =
@@ -529,7 +529,7 @@ object desugar {
529
529
// but not on the constructor parameters. The reverse is true for
530
530
// annotations on class _value_ parameters.
531
531
val constrTparams = impliedTparams.map(toDefParam(_, keepAnnotations = false ))
532
- val constrVparamss =
532
+ def defVparamss =
533
533
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
534
534
if (isCaseClass)
535
535
report.error(CaseClassMissingParamList (cdef), namePos)
@@ -540,6 +540,7 @@ object desugar {
540
540
ListOfNil
541
541
}
542
542
else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = true , keepDefault = true ))
543
+ val constrVparamss = defVparamss
543
544
val derivedTparams =
544
545
constrTparams.zipWithConserve(impliedTparams)((tparam, impliedParam) =>
545
546
derivedTypeParam(tparam).withAnnotations(impliedParam.mods.annotations))
@@ -614,6 +615,11 @@ object desugar {
614
615
case _ => false
615
616
}
616
617
618
+ def isRepeated (tree : Tree ): Boolean = stripByNameType(tree) match {
619
+ case PostfixOp (_, Ident (tpnme.raw.STAR )) => true
620
+ case _ => false
621
+ }
622
+
617
623
def appliedRef (tycon : Tree , tparams : List [TypeDef ] = constrTparams, widenHK : Boolean = false ) = {
618
624
val targs = for (tparam <- tparams) yield {
619
625
val targ = refOfDef(tparam)
@@ -630,10 +636,13 @@ object desugar {
630
636
appliedTypeTree(tycon, targs)
631
637
}
632
638
633
- def isRepeated (tree : Tree ): Boolean = stripByNameType(tree) match {
634
- case PostfixOp (_, Ident (tpnme.raw.STAR )) => true
635
- case _ => false
636
- }
639
+ def addParamRefinements (core : Tree , paramss : List [List [ValDef ]]): Tree =
640
+ val refinements =
641
+ for params <- paramss; param <- params; if param.mods.is(Tracked ) yield
642
+ ValDef (param.name, SingletonTypeTree (TermRefTree ().watching(param)), EmptyTree )
643
+ .withSpan(param.span)
644
+ if refinements.isEmpty then core
645
+ else RefinedTypeTree (core, refinements).showing(i " refined result: $result" , Printers .desugar)
637
646
638
647
// a reference to the class type bound by `cdef`, with type parameters coming from the constructor
639
648
val classTypeRef = appliedRef(classTycon)
@@ -854,18 +863,17 @@ object desugar {
854
863
Nil
855
864
}
856
865
else {
857
- val defParamss = constrVparamss match {
866
+ val defParamss = defVparamss match
858
867
case Nil :: paramss =>
859
868
paramss // drop leading () that got inserted by class
860
869
// TODO: drop this once we do not silently insert empty class parameters anymore
861
870
case paramss => paramss
862
- }
863
871
val finalFlag = if ctx.settings.YcompileScala2Library .value then EmptyFlags else Final
864
872
// implicit wrapper is typechecked in same scope as constructor, so
865
873
// we can reuse the constructor parameters; no derived params are needed.
866
874
DefDef (
867
875
className.toTermName, joinParams(constrTparams, defParamss),
868
- classTypeRef, creatorExpr)
876
+ addParamRefinements( classTypeRef, defParamss) , creatorExpr)
869
877
.withMods(companionMods | mods.flags.toTermFlags & (GivenOrImplicit | Inline ) | finalFlag)
870
878
.withSpan(cdef.span) :: Nil
871
879
}
0 commit comments