checker: allow using ! and ~ on aliased bool and integral types (#19403)

This commit is contained in:
Swastik Baranwal 2023-09-21 22:16:26 +05:30 committed by GitHub
parent c075e44ec1
commit 5ddbbfcfd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -4182,12 +4182,10 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
}
}
}
if node.op == .bit_not && !c.unwrap_generic(right_type).is_int() && !c.pref.translated
&& !c.file.is_translated {
if node.op == .bit_not && !right_sym.is_int() && !c.pref.translated && !c.file.is_translated {
c.type_error_for_operator('~', 'integer', right_sym.name, node.pos)
}
if node.op == .not && right_type != ast.bool_type_idx && !c.pref.translated
&& !c.file.is_translated {
if node.op == .not && right_sym.kind != .bool && !c.pref.translated && !c.file.is_translated {
c.type_error_for_operator('!', 'bool', right_sym.name, node.pos)
}
// FIXME

View File

@ -0,0 +1,7 @@
type JBoolean = bool
fn test_alias_not_op() {
a := JBoolean(false)
b := !a
assert b == true
}