1
0
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:
Alexander Medvednikov 2021-06-12 14:35:33 +03:00
parent 652e7ba973
commit 635f045b14
3 changed files with 10 additions and 2 deletions

View File

@ -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]

View File

@ -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 {

View File

@ -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 {