msvc: fix self compile, by avoiding explicit casting to the same type

pull/4345/head
Delyan Angelov 2020-04-11 13:35:41 +03:00
parent b10fcc79ba
commit 15f4594e44
1 changed files with 10 additions and 4 deletions

View File

@ -752,10 +752,9 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
mut full_const_name := if it.mod == 'main' { it.name } else { it.mod + '.' +
it.name }
if obj := c.file.global_scope.find_const(full_const_name) {
cf := ast.ConstField(obj)
if cint := is_const_integer(cf) {
fixed_size = cint.val.int()
}
if cint := const_int_value( obj ) {
fixed_size = cint
}
} else {
c.error('non existant integer const $full_const_name while initializing the size of a static array',
array_init.pos)
@ -772,6 +771,13 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
return array_init.typ
}
fn const_int_value(cfield ast.ConstField) ?int {
if cint := is_const_integer(cfield) {
return cint.val.int()
}
return none
}
fn is_const_integer(cfield ast.ConstField) ?ast.IntegerLiteral {
match cfield.expr {
ast.IntegerLiteral {