@register_passable("trivial")
struct OurBool:
var value: __mlir_type.i1
fn __init__(value: __mlir_type.i1) -> Self:
return Self {value: value}
fn __bool__(self) -> Bool:
return Bool(self.value)
fn main():
let a = OurBool(__mlir_attr.`true`)
if a:
print('a is True')
# This works
print(a)
# This does not:
# /home/danil/source/mjtest/main.mojo:37:10: error: no matching function in call to 'print':
# print(a)
# ...
# /home/danil/source/mjtest/main.mojo:1:1: note: candidate not viable: argument #0 cannot be converted from 'OurBool' to 'Bool'
# alias OurTrue = OurBool(__mlir_attr.`true`)
print(Bool(a))
# The explicit conversion does not work too
@register_passable("trivial")
struct OurBool:
var value: __mlir_type.i1
fn __init__(value: __mlir_type.i1) -> Self:
return Self {value: value}
fn __bool__(self) -> Bool:
return Bool(self.value)
fn main():
let a = OurBool(__mlir_attr.`true`)
if a:
print('a is True')
# This works
print(a)
# This does not:
# /home/danil/source/mjtest/main.mojo:37:10: error: no matching function in call to 'print':
# print(a)
# ...
# /home/danil/source/mjtest/main.mojo:1:1: note: candidate not viable: argument #0 cannot be converted from 'OurBool' to 'Bool'
# alias OurTrue = OurBool(__mlir_attr.`true`)
print(Bool(a))
# The explicit conversion does not work too