from std.collections import List from std.utils import Variant
comptime EvalResult = Variant[List[Int]]
def _first_value(result: EvalResult) → EvalResult:
var r = result
ref nodes = r[List[Int]] if len(nodes) > 0: return EvalResult(nodes[0]) # This is a type error
return result
def main() raises: # Intentionally do not call `_first_value`; keeps the type error latent.
pass
The code above has a typing error: nodes[0] is a single Int which is not a member of the Variant.
I would expect the Mojo compiler to detect this, but when _first_value is not called, it happily accepts the latent issue.
In the full application, the code containing the type error is live but called indirectly - the compiler misses the type error, and it causes random runtime crashes that are hard to debug.
Yes, that is the original bug I reported. I now found it’s triggered by a “hidden” type error.
It’s an insidious issue that’s been blocking me from exploring Mojo further over the past few weeks. As a user I trust the compiler to enforce strict typing, as promised. I hope the Mojo team can acknowledge the urgency of fixing this