input-output-hk / input-output-hk/PlutusCoreBlaster

[Bug]: MkCons skips Haskell's element/list type-tag check

Open Beginner friendly
#37 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Lean
Stars
14
Forks
6
Avg merge
4d 8h
Merged PRs (30d)
2

Description

## Description

Haskell's `MkCons` checks that the element being consed matches the existing list's element type, failing evaluation on a mismatch (e.g. consing a `Bool` onto a `list(integer)`). Lean's `mkCons` (`PlutusCore/UPLC/BuiltinFunctions/List.lean`) had no such check for the generic `ConstList` case -- it accepted any `Const` value unconditionally, silently building a heterogeneous list where Haskell raises an evaluation error.

Note: this can only be caught when the existing list is non-empty. Lean's `Const.ConstList` doesn't retain a declared element type once the list is empty -- that information is only available during decoding (`TextEncoding/Basic.lean`'s `parseConstList`) and is discarded once the value is constructed, so `(con (list bool) [])` and `(con (list integer) [])` are indistinguishable at runtime. Consing a wrongly-typed element onto an *empty* list therefore still can't be caught without a representation change (adding a type witness to `Const.ConstList` and threading it through every consumer). This issue and its fix cover only the non-empty case, which is what the official conformance test actually exercises.

## Steps to Reproduce

```lean
import PlutusCore.UPLC.BuiltinFunctions.List
import PlutusCore.UPLC.CekValue

open PlutusCore.UPLC.BuiltinFunctions.List
open PlutusCore.UPLC.CekValue

-- Consing a Bool onto a non-empty list(integer).
#eval mkCons
[ CekValue.VCon (Const.ConstList [Const.Integer 1, Const.Integer 2])
, CekValue.VCon (Const.Bool true)
]
```

## Expected Behavior

Should return `none` (builtin failure), matching Haskell rejecting the type mismatch.

## Actual Behavior

Returns `some (CekValue.VCon (Const.ConstList [Const.Bool true, Const.Integer 1, Const.Integer 2]))` -- silently builds a heterogeneous list.

## Lean Version

v4.24.0

## Z3 Version

N/A (no SMT tactics involved)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in PlutusCore/UPLC/BuiltinFunctions/List.lean at Lean's mkCons implementation and run the provided non-empty list reproduction. Done means a mismatched element returns none, matching Haskell's behavior, while the documented empty-list limitation remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.