Skip to content

Commit 3205dd2

Browse files
[expr] Add fallback for MYNEWT_VAL_ prefix identifiers
Some settings may reference values with MYNEWT_VAL_ prefix - this was done to actually evaluate them as expression in preprocessor. We can fix those and emit warning instead of failing.
1 parent d5ae4e7 commit 3205dd2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

newt/syscfg/eval.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"go/token"
2727
"mynewt.apache.org/newt/util"
2828
"strconv"
29+
"strings"
2930
)
3031

3132
func int2bool(x int) bool {
@@ -275,7 +276,18 @@ func (cfg *Cfg) exprEvalIdentifier(e *ast.Ident) (interface{}, error) {
275276

276277
entry, ok := cfg.Settings[name]
277278
if !ok {
278-
return 0, util.FmtNewtError("Undefined identifier referenced: %s", name)
279+
fixedName := name
280+
if strings.HasPrefix(fixedName, SYSCFG_PREFIX_SETTING) {
281+
fixedName = strings.TrimPrefix(fixedName, SYSCFG_PREFIX_SETTING)
282+
}
283+
284+
entry, ok = cfg.Settings[fixedName]
285+
if !ok {
286+
return 0, util.FmtNewtError("Undefined identifier referenced: %s", name)
287+
}
288+
289+
util.OneTimeWarning("Referenced identifier \"%s\" does not exist, did you mean \"%s\"?",
290+
name, fixedName)
279291
}
280292

281293
var val interface{}

0 commit comments

Comments
 (0)