Skip to content

Issues with type inference for annotated list literals #1359

Closed
@sjakobi

Description

@sjakobi
  1. It's redundant to check the kind of the type parameter starting in line 606. Type-inference for List already covers this.

    ListLit (Just _T₀) ts -> do
    _ <- loop ctx _T₀
    let _T₀' = eval values _T₀
    let _T₀'' = quote names _T₀'
    case _T₀' of
    VList _T₁' -> do
    tT₁' <- loop ctx (quote names _T₁')
    case tT₁' of
    VConst Type -> return ()
    _ -> die (InvalidListType _T₀'')
    _ -> do
    die (InvalidListType _T₀'')

  2. The subsequent check of the list elements is both wrong and apparently dead code, according to coverage reports. We're trying to compare the type of an element with the full List X annotation. If these were equivalent, the list would actually by ill-typed!

let process i t = do
_T₁' <- loop ctx t
if Eval.conv values _T₀' _T₁'
then return ()
else do
let _T₁'' = quote names _T₁'
die (InvalidListElement i _T₀'' t _T₁'')
traverseWithIndex_ process ts

I think it would be best to completely get rid of the element processing here, but I'm not sure what would be the best way…

A) Pattern match for ListLit (Just _) [] and throw a BrokenInvariant error.
B) Redefine the ListLit constructor to contain a Either (Expr s a) (NonEmptySeq (Expr s a))
C) Make separate constructors for empty and non-empty lists.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions