codon
codon copied to clipboard
Handling a self-defined error leads to the failure of codon
We define a attributeError in the following code. Then we raise and catch it. The expected behavior is that the compiler can handle it well and print "hi", while codon fails. CPython can work well with this case.
test.py
class B:
def __bool__(self):
raise AttributeError("don't do that!")
b = B()
try:
if b:
pass
except AttributeError:
print("HI")
Reproduce: codon/codon-linux-x86_64/codon-deploy/bin/codon' run -release test.py
Crash message:
Trunc only operates on integer
%238 = trunc {} %220 to i1, !dbg !2405
Assert failed: module broken
Expression: !broken
Source: /github/workspace/codon/cir/llvm/optimize.cpp:601
Aborted (core dumped)
Behavior on CPython 3.10.8: work well
Environment: codon: v0.15.5 on Feb 6 Ubuntu 18.04
The following code works as expected:
class B:
def __bool__(self) -> bool:
raise AttributeError("don't do that!")
b = B()
try:
if b:
pass
except AttributeError:
print("HI")
I think its easier to list cases when codon actually works, than crashes :) And there are no updates for long time.
Thanks for the report — it seems there’s a check missing in the type checker to ensure __bool__
actually returns a boolean. We’ll fix it in the next release.
We plan to put out v0.16 in the next couple weeks. We’re a small team currently so appreciate your patience.
Thanks for your confirmation. I hope these bugs are helpful for the development of codon.