Skip to content

Commit

Permalink
Merge pull request #519 from nevalang/human_readable_err_for_incompat…
Browse files Browse the repository at this point in the history
…_conn_type

fix(typesys): expr stringer + e2e
  • Loading branch information
emil14 committed Mar 13, 2024
2 parents 643486f + 84c4c90 commit de70d7d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@
"cwd": "${workspaceFolder}/e2e/tests/struct_selector_on_port_addr",
"args": ["run", "main"]
},
{
"name": "E2E incompat_comp_type_arg",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/e2e/tests/incompat_comp_type_arg",
"args": ["run", "main"]
},
// === LSP ===
{
"name": "LSP",
Expand Down
19 changes: 19 additions & 0 deletions e2e/run_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,22 @@ func TestListWithNegInt(t *testing.T) {
require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
}

func TestIncompatCompTypeArg(t *testing.T) {
err := os.Chdir("./tests/incompat_comp_type_arg")
require.NoError(t, err)

defer os.Chdir(wd)

cmd := exec.Command("neva", "run", "main")

out, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Equal(
t,
"main/main.neva:2:9 Incompatible types: want int | float | string, got any\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
10 changes: 10 additions & 0 deletions e2e/tests/incompat_comp_type_arg/main/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
component Main(start) (stop) {
nodes { Eq<any> }
net {
:start -> (
0 -> eq:a,
1 -> eq:b
)
eq:else -> :stop
}
}
1 change: 1 addition & 0 deletions e2e/tests/incompat_comp_type_arg/neva.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neva: 0.10.0
2 changes: 1 addition & 1 deletion internal/compiler/analyzer/component_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (a Analyzer) analyzeComponentNode(
); err != nil {
return src.Node{}, src.Interface{}, &compiler.Error{
Err: err,
Location: &location,
Location: &scope.Location,
Meta: &node.Meta,
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/typesystem/subtype_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
ErrStructLen = errors.New("Subtype struct must contain >= fields than supertype")
ErrStructField = errors.New("Subtype struct field must be subtype of corresponding supertype field")
ErrStructNoField = errors.New("Subtype struct is missing field of supertype")
ErrUnion = errors.New("Subtype must be subtype of supertype union")
ErrUnion = errors.New("Incompatible types")
ErrUnionsLen = errors.New("Subtype union must be <= supertype union")
ErrUnions = errors.New("Subtype union el must be subtype of supertype union")
ErrDiffLitTypes = errors.New("Subtype and supertype lits must be of the same type")
Expand Down Expand Up @@ -163,7 +163,7 @@ func (s SubtypeChecker) Check( //nolint:funlen,gocognit,gocyclo
return nil
}
}
return fmt.Errorf("%w: want %v, got %v", ErrUnion, constr.Lit.Union, expr)
return fmt.Errorf("%w: want %v, got %v", ErrUnion, constr, expr)
}
// If we here, then expr is union
if len(expr.Lit.Union) > len(constr.Lit.Union) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/typesystem/typesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type Expr struct {
type ExprMeta any

// String formats expression in a TS manner
func (expr *Expr) String() string {
if expr == nil || expr.Inst == nil && expr.Lit == nil {
func (expr Expr) String() string {
if expr.Inst == nil && expr.Lit == nil {
return "empty"
}

Expand Down

0 comments on commit de70d7d

Please sign in to comment.