Skip to content

Commit 8b8a626

Browse files
committed
fix python wrappers bool being accepted as integers
1 parent 04d7031 commit 8b8a626

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/conversions/src/RLCToPython.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,16 @@ namespace mlir::rlc
450450
w.write(" and isinstance(args[", argument.index() - isMethod, "], ");
451451
w.writeType(argument.value());
452452
w.write(")");
453+
454+
// bool in python are integers too, so we have to guard against bools
455+
// when we can accept a int
456+
if (argument.value().isa<mlir::rlc::IntegerType>())
457+
{
458+
w.write(
459+
" and not isinstance(args[",
460+
argument.index() - isMethod,
461+
"], builtins.bool)");
462+
}
453463
}
454464
w.writenl(":");
455465
auto _ = w.indent();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RUN: split-file %s %t
2+
# RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared --pyrlc-lib=%pyrlc_lib
3+
# RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python
4+
# RUN: python %t/to_run.py
5+
6+
#--- source.rl
7+
fun<T> this_one(T i) -> StringLiteral:
8+
if i is Int:
9+
return "int"
10+
if i is Bool:
11+
return "bool"
12+
return "none"
13+
14+
fun asd():
15+
this_one(1)
16+
this_one(true)
17+
18+
#--- to_run.py
19+
import wrapper
20+
21+
assert(wrapper.this_one(True).decode("utf-8") == 'bool')

0 commit comments

Comments
 (0)