diff options
-rw-r--r-- | builder/build.go | 4 | ||||
-rw-r--r-- | builder/error.go | 8 | ||||
-rw-r--r-- | diagnostics/diagnostics.go | 23 | ||||
-rw-r--r-- | testdata/errors/compiler.go | 3 | ||||
-rw-r--r-- | testdata/errors/optimizer.go | 1 |
5 files changed, 21 insertions, 18 deletions
diff --git a/builder/build.go b/builder/build.go index 50ec04d9d..49aad5c79 100644 --- a/builder/build.go +++ b/builder/build.go @@ -375,7 +375,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe defer mod.Context().Dispose() defer mod.Dispose() if errs != nil { - return newMultiError(errs) + return newMultiError(errs, pkg.ImportPath) } if err := llvm.VerifyModule(mod, llvm.PrintMessageAction); err != nil { return errors.New("verification error after compiling package " + pkg.ImportPath) @@ -1130,7 +1130,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues m // O0/O1/O2/Os/Oz optimization pipeline). errs := transform.Optimize(mod, config) if len(errs) > 0 { - return newMultiError(errs) + return newMultiError(errs, "") } if err := llvm.VerifyModule(mod, llvm.PrintMessageAction); err != nil { return errors.New("verification failure after LLVM optimization passes") diff --git a/builder/error.go b/builder/error.go index 0f920a031..3531007fb 100644 --- a/builder/error.go +++ b/builder/error.go @@ -3,7 +3,8 @@ package builder // MultiError is a list of multiple errors (actually: diagnostics) returned // during LLVM IR generation. type MultiError struct { - Errs []error + ImportPath string + Errs []error } func (e *MultiError) Error() string { @@ -15,14 +16,15 @@ func (e *MultiError) Error() string { // newMultiError returns a *MultiError if there is more than one error, or // returns that error directly when there is only one. Passing an empty slice // will lead to a panic. -func newMultiError(errs []error) error { +// The importPath may be passed if this error is for a single package. +func newMultiError(errs []error, importPath string) error { switch len(errs) { case 0: panic("attempted to create empty MultiError") case 1: return errs[0] default: - return &MultiError{errs} + return &MultiError{importPath, errs} } } diff --git a/diagnostics/diagnostics.go b/diagnostics/diagnostics.go index f9261e292..e58becfb8 100644 --- a/diagnostics/diagnostics.go +++ b/diagnostics/diagnostics.go @@ -43,17 +43,10 @@ func CreateDiagnostics(err error) ProgramDiagnostic { if err == nil { return nil } - switch err := err.(type) { - case *builder.MultiError: - var diags ProgramDiagnostic - for _, err := range err.Errs { - diags = append(diags, createPackageDiagnostic(err)) - } - return diags - default: - return ProgramDiagnostic{ - createPackageDiagnostic(err), - } + // Right now, the compiler will only show errors for the first pacakge that + // fails to build. This is likely to change in the future. + return ProgramDiagnostic{ + createPackageDiagnostic(err), } } @@ -63,6 +56,14 @@ func createPackageDiagnostic(err error) PackageDiagnostic { // Extract diagnostics for this package. var pkgDiag PackageDiagnostic switch err := err.(type) { + case *builder.MultiError: + if err.ImportPath != "" { + pkgDiag.ImportPath = err.ImportPath + } + for _, err := range err.Errs { + diags := createDiagnostics(err) + pkgDiag.Diagnostics = append(pkgDiag.Diagnostics, diags...) + } case loader.Errors: if err.Pkg != nil { pkgDiag.ImportPath = err.Pkg.ImportPath diff --git a/testdata/errors/compiler.go b/testdata/errors/compiler.go index fb0057c93..3332c7c2f 100644 --- a/testdata/errors/compiler.go +++ b/testdata/errors/compiler.go @@ -7,7 +7,6 @@ func foo() { //go:align 7 var global int -// TODO: include package name in the error message - +// ERROR: # command-line-arguments // ERROR: compiler.go:4:6: can only use //go:wasmimport on declarations // ERROR: compiler.go:8:5: global variable alignment must be a positive power of two diff --git a/testdata/errors/optimizer.go b/testdata/errors/optimizer.go index 4e0d71b93..c2e0b9c4b 100644 --- a/testdata/errors/optimizer.go +++ b/testdata/errors/optimizer.go @@ -14,5 +14,6 @@ func main() { }) } +// ERROR: # command-line-arguments // ERROR: optimizer.go:9:15: interrupt ID is not a constant // ERROR: optimizer.go:13:15: interrupt ID is not a constant |