From 1875cc5f8fc392d183fcea8d6e88211cd6645904 Mon Sep 17 00:00:00 2001 From: David Pearce Date: Sat, 21 Dec 2024 22:04:38 +1300 Subject: [PATCH] fix incorrect error for invalid type (#484) In a specific situation, the parser was "losing" error messages and that was causing big problems downstream. --- pkg/corset/parser.go | 4 ++-- pkg/test/invalid_corset_test.go | 4 ++++ testdata/basic_invalid_13.lisp | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 testdata/basic_invalid_13.lisp diff --git a/pkg/corset/parser.go b/pkg/corset/parser.go index bff6a4b..80f9e63 100644 --- a/pkg/corset/parser.go +++ b/pkg/corset/parser.go @@ -193,8 +193,8 @@ func (p *Parser) parseModuleContents(module string, terms []sexp.SExp) ([]Declar err := p.translator.SyntaxError(s, "unexpected or malformed declaration") errors = append(errors, *err) } else if e.MatchSymbols(2, "module") { - return decls, terms[i:], nil - } else if decl, errs := p.parseDeclaration(module, e); errs != nil { + return decls, terms[i:], errors + } else if decl, errs := p.parseDeclaration(module, e); len(errs) > 0 { errors = append(errors, errs...) } else { // Continue accumulating declarations for this module. diff --git a/pkg/test/invalid_corset_test.go b/pkg/test/invalid_corset_test.go index ea77bbe..bc94688 100644 --- a/pkg/test/invalid_corset_test.go +++ b/pkg/test/invalid_corset_test.go @@ -68,6 +68,10 @@ func Test_Invalid_Basic_12(t *testing.T) { CheckInvalid(t, "basic_invalid_12") } +func Test_Invalid_Basic_13(t *testing.T) { + CheckInvalid(t, "basic_invalid_13") +} + // =================================================================== // Constant Tests // =================================================================== diff --git a/testdata/basic_invalid_13.lisp b/testdata/basic_invalid_13.lisp new file mode 100644 index 0000000..debe9f4 --- /dev/null +++ b/testdata/basic_invalid_13.lisp @@ -0,0 +1,7 @@ +;;error:4:22-26:unknown type +(module mmio) + +(defcolumns (COUNTER :dac)) +(defalias CT COUNTER) + +(module mmio)