Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Feb 13, 2024
1 parent 2497d4c commit b714e99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 8 additions & 11 deletions tools/analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func TestParseError(t *testing.T) {
importRange ast.Range,
) ([]byte, error) {
switch location {
case contractLocation:
return []byte(contractCode), nil
default:
require.FailNowf(t,
"import of unknown location",
Expand Down Expand Up @@ -301,12 +303,12 @@ func TestHandledParserError(t *testing.T) {
},
}

require.Equal(t, 1, handlerCalls)

programs, err := analysis.Load(config, contractLocation)
require.NoError(t, err)

var parserError *parser.Error
require.Equal(t, 1, handlerCalls)

var parserError parser.Error
require.ErrorAs(t, programs[contractLocation].LoadError, &parserError)
}

Expand Down Expand Up @@ -354,9 +356,8 @@ func TestHandledCheckerError(t *testing.T) {
},
}

require.Equal(t, 1, handlerCalls)

programs, err := analysis.Load(config, contractLocation)
require.Equal(t, 1, handlerCalls)
require.NoError(t, err)

var checkerError *sema.CheckerError
Expand Down Expand Up @@ -423,9 +424,8 @@ func TestHandledLoadErrorImportedProgram(t *testing.T) {
},
}

require.Equal(t, 2, handlerCalls)

programs, err := analysis.Load(config, contract1Location)
require.Equal(t, 2, handlerCalls)
require.NoError(t, err)

var checkerError *sema.CheckerError
Expand All @@ -434,10 +434,7 @@ func TestHandledLoadErrorImportedProgram(t *testing.T) {

// Validate that parent checker receives the imported program error despite it being handled
var importedProgramErr *sema.ImportedProgramError
loadErr := programs[contract1Location].LoadError.(analysis.ParsingCheckingError)
unwrapedErr := loadErr.Unwrap().(*sema.CheckerError)
require.Len(t, unwrapedErr.ChildErrors(), 1)
require.ErrorAs(t, unwrapedErr.ChildErrors()[0], &importedProgramErr)
require.ErrorAs(t, programs[contract1Location].LoadError, &importedProgramErr)
}

func TestStdlib(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions tools/analysis/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ func (programs Programs) check(
return nil, err
}

program := programs[importedLocation]
checker := program.Checker

// If the imported program has a checker, use its elaboration for the import
if programs[importedLocation].Checker != nil {
elaboration = programs[importedLocation].Checker.Elaboration
if checker != nil {
elaboration = checker.Elaboration
}

// If the imported program had an error while loading, record it
loadError = programs[importedLocation].LoadError
loadError = program.LoadError
}

if loadError != nil {
Expand Down

0 comments on commit b714e99

Please sign in to comment.