checker: do not require fn main when building an object file

master
Alexander Medvednikov 2022-06-06 12:29:46 +03:00
parent ce771876a3
commit e89a6269e4
2 changed files with 4 additions and 3 deletions

View File

@ -368,7 +368,7 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
if !has_main_mod_file { if !has_main_mod_file {
c.error('project must include a `main` module or be a shared library (compile with `v -shared`)', c.error('project must include a `main` module or be a shared library (compile with `v -shared`)',
token.Pos{}) token.Pos{})
} else if !has_main_fn { } else if !has_main_fn && !c.pref.is_o {
c.error('function `main` must be declared in the main module', token.Pos{}) c.error('function `main` must be declared in the main module', token.Pos{})
} }
} }

View File

@ -5486,8 +5486,9 @@ fn (mut g Gen) enum_val(node ast.EnumVal) {
// && g.inside_switch // && g.inside_switch
if g.pref.translated && node.typ.is_number() { if g.pref.translated && node.typ.is_number() {
// Mostly in translated code, when C enums are used as ints in switches // Mostly in translated code, when C enums are used as ints in switches
sym := g.table.sym(node.typ) // sym := g.table.sym(node.typ)
g.write('/* $node enum val is_number $node.mod styp=$styp sym=$sym*/_const_main__$node.val') // g.write('/* $node enum val is_number $node.mod styp=$styp sym=$sym*/_const_main__$node.val')
g.write('_const_main__$node.val')
} else { } else {
g.write('${styp}__$node.val') g.write('${styp}__$node.val')
} }