From 8ade188e0d18d66c1e8d33d30d24fa10109aa503 Mon Sep 17 00:00:00 2001 From: Shib Date: Wed, 13 Apr 2022 15:03:36 +0200 Subject: [PATCH] Fix (gen.c) -> Fixed attribute without its value is now an error --- vlib/v/gen/c/cgen.v | 4 +--- vlib/v/gen/c/fn.v | 4 +--- vlib/v/parser/fn.v | 10 +++++----- vlib/v/parser/parse_type.v | 10 +++++----- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 0938b70db6..f246f3651e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1349,9 +1349,7 @@ pub fn (mut g Gen) write_fn_typesymbol_declaration(sym ast.TypeSymbol) { for attr in func.attrs { match attr.name { 'callconv' { - if attr.has_arg { - call_conv = '__$attr.arg ' - } + call_conv = '__$attr.arg ' } else {} } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 520267b213..1299fdbdcc 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2154,9 +2154,7 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string { fn_attrs += '__fastcall ' } "callconv" { - if attr.has_arg { - fn_attrs += '__$attr.arg ' - } + fn_attrs += '__$attr.arg ' } 'console' { g.force_main_console = true diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 4bdc619337..8bb8c6e0e2 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -230,11 +230,11 @@ fn (mut p Parser) fn_decl() ast.FnDecl { p.tok.pos()) } 'callconv' { - if fna.has_arg { - if fna.arg !in ['stdcall', 'fastcall', 'cdecl'] { - p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', - p.tok.pos()) - } + if !fna.has_arg { + p.error_with_pos('callconv attribute is present but its value is missing', p.prev_tok.pos()) + } + if fna.arg !in ['stdcall', 'fastcall', 'cdecl'] { + p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', p.prev_tok.pos()) } } else {} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index ed709aeb58..ca887856dc 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -233,11 +233,11 @@ pub fn (mut p Parser) parse_fn_type(name string) ast.Type { for attr in p.attrs { match attr.name { 'callconv' { - if attr.has_arg { - if attr.arg !in ['stdcall', 'fastcall', 'cdecl'] { - p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', - p.prev_tok.pos()) - } + if !attr.has_arg { + p.error_with_pos('callconv attribute is present but its value is missing', p.prev_tok.pos()) + } + if attr.arg !in ['stdcall', 'fastcall', 'cdecl'] { + p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', p.prev_tok.pos()) } } else {}