Skip to content

Commit dce1707

Browse files
committed
Add Recheck
1 parent 3468fa5 commit dce1707

File tree

3 files changed

+292
-70
lines changed

3 files changed

+292
-70
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,24 @@ object NamerOps:
177177
cls.registeredCompanion = modcls
178178
modcls.registeredCompanion = cls
179179

180+
/** For secondary constructors, make it known in the context that their type parameters
181+
* are aliases of the class type parameters. This is done by (ab?)-using GADT constraints.
182+
* See pos/i941.scala
183+
*/
184+
def linkConstructorParams(sym: Symbol)(using Context): Context =
185+
if sym.isConstructor && !sym.isPrimaryConstructor then
186+
sym.rawParamss match
187+
case (tparams @ (tparam :: _)) :: _ if tparam.isType =>
188+
val rhsCtx = ctx.fresh.setFreshGADTBounds
189+
rhsCtx.gadt.addToConstraint(tparams)
190+
tparams.lazyZip(sym.owner.typeParams).foreach { (psym, tparam) =>
191+
val tr = tparam.typeRef
192+
rhsCtx.gadt.addBound(psym, tr, isUpper = false)
193+
rhsCtx.gadt.addBound(psym, tr, isUpper = true)
194+
}
195+
rhsCtx
196+
case _ =>
197+
ctx
198+
else ctx
199+
180200
end NamerOps
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package dotty.tools.dotc
2+
package transform
3+
4+
import core.Phases.Phase
5+
import core.DenotTransformers.IdentityDenotTransformer
6+
import core.Contexts.{Context, ctx}
7+
8+
/** A phase that precedes the rechecker and that allows installing
9+
* new types for local symbols.
10+
*/
11+
class PreRecheck extends Phase, IdentityDenotTransformer:
12+
13+
def phaseName: String = "preRecheck"
14+
15+
override def isEnabled(using Context) = next.isEnabled
16+
17+
override def changesBaseTypes: Boolean = true
18+
19+
def run(using Context): Unit = ()
20+
21+
override def isCheckable = false

0 commit comments

Comments
 (0)