Skip to content

substTm mixes up term and type vars #1046

Description

@martijnbastiaan

Consider two variables. One is a term variable:

termVar :: Var Term
termVar = Id {
    varName = fakeName {nameUniq=unique, nameOcc="term"}
  , varUniq = unique
  , varType = ConstTy (TyCon fakeName)
  , idScope = LocalId
  }

and the other a type variable

typeVar :: Var Type
typeVar = TyVar {
    varName = fakeName {nameUniq=unique, nameOcc="type"}
  , varUniq = unique
  , varType = ConstTy (TyCon fakeName)
  }

We'd expect that deshadowing Var termVar with an inScopeSet of just typeVar should be a no-op, as their uniques live in different name spaces. (In fact, it's not even possible to have both termVar and typeVar in an InScopeSet, as it only stores uniques!). deShadowTerm currently behaves differently though:

>>> deShadowTerm (extendInScopeSet emptyInScopeSet typeVar) (Var termVar)
Var (TyVar {varName = Name {nameSort = User, nameOcc = "type", nameUniq = 20, nameLoc = UnhelpfulSpan "<no location info>"}, varUniq = 20, varType = ConstTy (TyCon (Name {nameSort = User, nameOcc = "fake", nameUniq = 0, nameLoc = UnhelpfulSpan "<no location info>"}))})

instead of:

>>> deShadowTerm (extendInScopeSet emptyInScopeSet typeVar) (Var termVar)
Var (Id {varName = Name {nameSort = User, nameOcc = "term", nameUniq = 20, nameLoc = UnhelpfulSpan "<no location info>"}, varUniq = 20, varType = ConstTy (TyCon (Name {nameSort = User, nameOcc = "fake", nameUniq = 0, nameLoc = UnhelpfulSpan "<no location info>"})), idScope = LocalId})

The culprit seems to be anti space-leak measures in lookupIdSubst:

| Just v' <- lookupInScope inScope v = Var (coerce v')

It should refuse to substitute TyVars with Ids.

Metadata

Metadata

Labels

bugpatch-providedPatch provided in comments: needs review, merge, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions