From da0bfa3ad0eb616692f0edb6b5805097e059a259 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 28 Jan 2018 11:46:25 +0100 Subject: Error out for malformed hex/int/string defaults Instead of failing in more cryptic ways later. Also use 'orig_type' instead of 'type' for the UNKNOWN check. Oversight. --- kconfiglib.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index e68e58f..362f099 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4168,11 +4168,25 @@ def _finalize_tree(node): def _check_sanity(sc): """ - Prints warnings for bad things that are easiest to check after parsing + Generates warnings or errors for bad things that are easiest to check after + parsing. sc: Symbol or Choice """ - if sc.type == UNKNOWN: + if sc.orig_type in (STRING, INT, HEX): + for sym, _ in sc.defaults: + if not isinstance(sym, Symbol) or \ + (sc.orig_type in (INT, HEX) and + (sym.is_constant or not sym.nodes) and + not _is_base_n(sym.str_value, _TYPE_TO_BASE[sc.orig_type])): + + raise KconfigSyntaxError( + "the {} symbol {} has a malformed default {}" + .format(TYPE_TO_STR[sc.orig_type], + _name_and_loc_str(sc), + expr_str(sym))) + + elif sc.orig_type == UNKNOWN: sc.kconfig._warn("{} defined without a type" .format(_name_and_loc_str(sc))) -- cgit v1.2.3