@@ -437,13 +437,13 @@ object desugar {
437437  private  def  toDefParam (tparam : TypeDef , keepAnnotations : Boolean ):  TypeDef  =  {
438438    var  mods  =  tparam.rawMods
439439    if  (! keepAnnotations) mods =  mods.withAnnotations(Nil )
440-     tparam.withMods(mods &  ( EmptyFlags   |   Sealed )  |  Param )
440+     tparam.withMods(mods &  EmptyFlags  |  Param )
441441  }
442442  private  def  toDefParam (vparam : ValDef , keepAnnotations : Boolean , keepDefault : Boolean ):  ValDef  =  {
443443    var  mods  =  vparam.rawMods
444444    if  (! keepAnnotations) mods =  mods.withAnnotations(Nil )
445445    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 )
447447  }
448448
449449  def  mkApply (fn : Tree , paramss : List [ParamClause ])(using  Context ):  Tree  = 
@@ -529,7 +529,7 @@ object desugar {
529529    //  but not on the constructor parameters. The reverse is true for
530530    //  annotations on class _value_ parameters.
531531    val  constrTparams  =  impliedTparams.map(toDefParam(_, keepAnnotations =  false ))
532-     val   constrVparamss  = 
532+     def   defVparamss  = 
533533      if  (originalVparamss.isEmpty) { //  ensure parameter list is non-empty
534534        if  (isCaseClass)
535535          report.error(CaseClassMissingParamList (cdef), namePos)
@@ -540,6 +540,7 @@ object desugar {
540540        ListOfNil 
541541      }
542542      else  originalVparamss.nestedMap(toDefParam(_, keepAnnotations =  true , keepDefault =  true ))
543+     val  constrVparamss  =  defVparamss
543544    val  derivedTparams  = 
544545      constrTparams.zipWithConserve(impliedTparams)((tparam, impliedParam) => 
545546        derivedTypeParam(tparam).withAnnotations(impliedParam.mods.annotations))
@@ -614,6 +615,11 @@ object desugar {
614615      case  _ =>  false 
615616    }
616617
618+     def  isRepeated (tree : Tree ):  Boolean  =  stripByNameType(tree) match  {
619+       case  PostfixOp (_, Ident (tpnme.raw.STAR )) =>  true 
620+       case  _ =>  false 
621+     }
622+ 
617623    def  appliedRef (tycon : Tree , tparams : List [TypeDef ] =  constrTparams, widenHK : Boolean  =  false ) =  {
618624      val  targs  =  for  (tparam <-  tparams) yield  {
619625        val  targ  =  refOfDef(tparam)
@@ -630,10 +636,13 @@ object desugar {
630636      appliedTypeTree(tycon, targs)
631637    }
632638
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)
637646
638647    //  a reference to the class type bound by `cdef`, with type parameters coming from the constructor
639648    val  classTypeRef  =  appliedRef(classTycon)
@@ -854,18 +863,17 @@ object desugar {
854863        Nil 
855864      }
856865      else  {
857-         val  defParamss  =  constrVparamss  match  { 
866+         val  defParamss  =  defVparamss  match 
858867          case  Nil  ::  paramss => 
859868            paramss //  drop leading () that got inserted by class
860869                    //  TODO: drop this once we do not silently insert empty class parameters anymore
861870          case  paramss =>  paramss
862-         }
863871        val  finalFlag  =  if  ctx.settings.YcompileScala2Library .value then  EmptyFlags  else  Final 
864872        //  implicit wrapper is typechecked in same scope as constructor, so
865873        //  we can reuse the constructor parameters; no derived params are needed.
866874        DefDef (
867875          className.toTermName, joinParams(constrTparams, defParamss),
868-           classTypeRef, creatorExpr)
876+           addParamRefinements( classTypeRef, defParamss) , creatorExpr)
869877          .withMods(companionMods |  mods.flags.toTermFlags &  (GivenOrImplicit  |  Inline ) |  finalFlag)
870878          .withSpan(cdef.span) ::  Nil 
871879      }
0 commit comments