Skip to content

Commit 1f41d86

Browse files
committed
lang: ast: Give resource-build errors a source byline
Storing an incompatible value into a resource field (e.g. a negative int into an unsigned field) surfaced from the interpret layer without any position. Attach the offending StmtResField's byline at the types.Into failure site so the user is pointed at the specific field, with a caret snippet, rather than the whole resource block.
1 parent 78e9ade commit 1f41d86

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lang/ast/structs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,9 @@ func (obj *StmtRes) resource(table interfaces.Table, resName, data string) (engi
11611161

11621162
// mutate the struct field f with the mcl data in fv
11631163
if err := types.Into(fv, f); err != nil {
1164-
return nil, err
1164+
// Point at the specific resource field in the source,
1165+
// e.g. storing a negative int into an unsigned field.
1166+
return nil, interfaces.HighlightHelper(x, x.data.Logf, err)
11651167
}
11661168
}
11671169

lang/interpret_test/TestAstFunc2/uint64-negative-wrap.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ test "t1" {
99
uint64 => $x,
1010
}
1111
-- OUTPUT --
12-
# err: errInterpret: error building resource: can't store negative int `-1` into unsigned `uint64` field
12+
# err: errInterpret: error building resource: can't store negative int `-1` into unsigned `uint64` field: /main.mcl @ 8:2-8:15

0 commit comments

Comments
 (0)