diff options
author | Martin Odersky <odersky@gmail.com> | 2014-12-11 18:47:18 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-12-16 17:46:14 +0100 |
commit | 16554c0efe2d09ab3ef760522f0811a964f7ee84 (patch) | |
tree | b3c94dc415850f264c16dbd0b91418e49947045a /src/dotty/tools/dotc/core/Contexts.scala | |
parent | 21fa5dd1a47727c977848163e2610be745951dbc (diff) | |
download | dotty-16554c0efe2d09ab3ef760522f0811a964f7ee84.tar.gz dotty-16554c0efe2d09ab3ef760522f0811a964f7ee84.tar.bz2 dotty-16554c0efe2d09ab3ef760522f0811a964f7ee84.zip |
Fixed #264 - failure to typecheck GADTs
The previous scheme derived the right bounds, but then failed to use them
because a TypeRef already has a set info (its bounds). Changing the bounds in
the symbol by a side effect does not affect that. This is good! But it showed
that the previous scheme was too fragile because it used a sneaky side effect
when updating the symbol info which failed to propgate into the cached
info in TypeRef.
We now keep GADT computed bounds separate form the symbol info
in a map `gadt` in the current context.
Diffstat (limited to 'src/dotty/tools/dotc/core/Contexts.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 805b7660c..2477fd4a4 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -146,6 +146,11 @@ object Contexts { protected def diagnostics_=(diagnostics: Option[StringBuilder]) = _diagnostics = diagnostics def diagnostics: Option[StringBuilder] = _diagnostics + /** The current bounds in force for type parameters appearing in a GADT */ + private var _gadt: GADTMap = _ + protected def gadt_=(gadt: GADTMap) = _gadt = gadt + def gadt: GADTMap = _gadt + /** A map in which more contextual properties can be stored */ private var _moreProperties: Map[String, Any] = _ protected def moreProperties_=(moreProperties: Map[String, Any]) = _moreProperties = moreProperties @@ -418,6 +423,8 @@ object Contexts { def setSetting[T](setting: Setting[T], value: T): this.type = setSettings(setting.updateIn(sstate, value)) + def setFreshGADTBounds: this.type = { this.gadt = new GADTMap(gadt.bounds); this } + def setDebug = setSetting(base.settings.debug, true) } @@ -439,6 +446,7 @@ object Contexts { moreProperties = Map.empty typeComparer = new TypeComparer(this) searchHistory = new SearchHistory(0, Map()) + gadt = new GADTMap(SimpleMap.Empty) } object NoContext extends Context { @@ -593,6 +601,8 @@ object Contexts { implicit val ctx: Context = initctx } + class GADTMap(var bounds: SimpleMap[Symbol, TypeBounds]) + /** Initial size of superId table */ private final val InitialSuperIdsSize = 4096 |