mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: make is_int() work with aliases
This commit is contained in:
parent
652e7ba973
commit
635f045b14
@ -635,7 +635,11 @@ pub fn (t &TypeSymbol) is_pointer() bool {
|
||||
|
||||
[inline]
|
||||
pub fn (t &TypeSymbol) is_int() bool {
|
||||
return t.kind in [.i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .int_literal, .rune]
|
||||
res := t.kind in [.i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .int_literal, .rune]
|
||||
if !res && t.kind == .alias {
|
||||
return (t.info as Alias).parent_type.is_number()
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
[inline]
|
||||
|
@ -3432,7 +3432,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
ast.PrefixExpr {
|
||||
// Do now allow `*x = y` outside `unsafe`
|
||||
if left.op == .mul {
|
||||
if !c.inside_unsafe {
|
||||
if !c.inside_unsafe && !c.pref.translated {
|
||||
c.error('modifying variables via dereferencing can only be done in `unsafe` blocks',
|
||||
node.pos)
|
||||
} else {
|
||||
|
@ -22,6 +22,10 @@ fn test_type_alias_v2() {
|
||||
assert f + f32(0.6) == f32(8.0)
|
||||
g := Myf64_2(10.4)
|
||||
assert g + 0.5 == 10.9
|
||||
// test ++ on an alias
|
||||
mut x := Myint(10)
|
||||
x++
|
||||
assert x == 11
|
||||
}
|
||||
|
||||
struct Mystruct {
|
||||
|
Loading…
Reference in New Issue
Block a user