fix: handle unhandled case in isCaptured (#1068)

Previously, this function missed a case, namely, one where the head of a
type definition contains a concrete struct, like `Maybe` with a variable
argument, `a`. That is,

```
(deftype (Foo (Maybe a)) [x (Maybe a)])
```

Would throw a type error. This commit fixes that issue.
This commit is contained in:
Scott Olsen 2020-12-13 17:38:26 -05:00 committed by GitHub
parent a0a3976441
commit 321671c74a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,7 +138,8 @@ canBeUsedAsMemberType typeEnv typeVariables ty xobj =
-- `a` may be used as a member, sans `f`, but `f` may not appear
-- without `a`.
isCaptured :: Ty -> Ty -> Bool
isCaptured t v@(VarTy _) = t == v
isCaptured v@(VarTy _) t@(VarTy _) = t == v
isCaptured sa@(StructTy (VarTy _) _) sb@(StructTy (VarTy _) _) = sa == sb
isCaptured t (StructTy (VarTy _) vars) = t `elem` vars
isCaptured _ _ = error "canbeusedasmembertype iscaptured"
isCaptured v@(VarTy _) (StructTy _ vars) = v `elem` vars
-- Not a variable.
isCaptured _ _ = True