Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better type errors #42

Merged
merged 11 commits into from
Mar 27, 2024
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ smallvec = { version = "1.11", features = [ "const_generics", "serde" ] }
serde = { version = "1.0", features = [ "derive", "rc" ] }
routecore = { version = "0.4.0", features = ["bgp", "bmp", "serde"] }
rotonda-store = { version = "0.3.0" }
miette = { version = "7.1.0", features = ["fancy"] }
clap = { version = "4.4.6", features = ["derive"] }
ariadne = "0.4.0"

[dev-dependencies]
env_logger = "0.10"
Expand Down
6 changes: 2 additions & 4 deletions examples/asn_in_out.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use roto::compiler::Compiler;

use roto::blocks::Scope::{self, FilterMap};
use roto::types::collections::Record;
use roto::types::typedef::TypeDef;
use roto::vm;
use roto::{pipeline, vm};

use routecore::asn::Asn;

Expand All @@ -16,7 +14,7 @@ fn test_data(
env_logger::init();

// Compile the source code in this example
let rotolo = Compiler::build(source_code)?;
let rotolo = pipeline::run_test(source_code, None)?;
let roto_pack = rotolo.retrieve_pack_as_refs(&name)?;

// BGP UPDATE message containing MP_REACH_NLRI path attribute,
Expand Down
6 changes: 2 additions & 4 deletions examples/eval.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use roto::compiler::compile::Compiler;

use roto::types::builtin::BuiltinTypeValue;
use roto::types::collections::{ElementTypeValue, List, Record};
use roto::types::typedef::TypeDef;
use roto::types::typevalue::TypeValue;
use roto::vm;
use roto::{pipeline, vm};
use roto::blocks::Scope::{self, FilterMap};

use routecore::bgp::communities::HumanReadableCommunity as Community;
Expand All @@ -17,7 +15,7 @@ fn test_data(
println!("Evaluate filter {}...", name);

// Compile the source code in this example
let rotolo = Compiler::build(source_code)?;
let rotolo = pipeline::run_test(source_code, None)?;
let roto_pack = rotolo.retrieve_pack_as_refs(&name)?;

// Create a payload type and instance to feed into a VM.
Expand Down
Empty file.
6 changes: 2 additions & 4 deletions examples/route.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use roto::compiler::Compiler;

use roto::types::builtin::{RawRouteWithDeltas, RotondaId, UpdateMessage, RouteStatus};
use roto::types::collections::Record;
use roto::types::typevalue::TypeValue;
use roto::vm;
use roto::{pipeline, vm};
use roto::blocks::Scope::{self, FilterMap};
use routecore::bgp::message::SessionConfig;
use routecore::bgp::message::nlri::{Nlri, BasicNlri};
Expand All @@ -16,7 +14,7 @@ fn test_data(
println!("Evaluate module {}...", name);

// Compile the source code in this example
let rotolo = Compiler::build(source_code)?;
let rotolo = pipeline::run_test(source_code, None)?;
let roto_pack = rotolo.retrieve_pack_as_refs(&name)?;

// BGP UPDATE message containing MP_REACH_NLRI path attribute,
Expand Down
8 changes: 8 additions & 0 deletions examples/type_errors/duplicate_fields.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Foo { a: U32, a: U32 } // should error here

filter foo {
define {
rx msg: U32;
a = Foo { };
}
}
11 changes: 11 additions & 0 deletions examples/type_errors/extra_data_field.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
filter foo {
define {
rx msg: RouteStatus;
}

term bar {
match msg with {
Stale(x) -> true, // should error here
}
}
}
9 changes: 9 additions & 0 deletions examples/type_errors/field_does_not_exist.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type Foo { a: U32 }

filter foo {
define {
rx msg: U32;
foo = Foo { a: 8 };
a = foo.b;
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/invalid_field_access.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: U32;
b = String.foo; // should error error: no field access on type
}
}
13 changes: 13 additions & 0 deletions examples/type_errors/match_on_record.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Foo { a: U32 }

filter foo {
define {
rx msg: Foo;
}

term bar {
match msg with {

}
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/method_does_not_exist.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: U32;
b = msg.foo(); // should error here
}
}
13 changes: 13 additions & 0 deletions examples/type_errors/mismatched_types.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
filter foo {
define {
rx msg: BmpMessage;
a = true;
b = 4;
}

term foo {
match {
a == b;
}
}
}
7 changes: 7 additions & 0 deletions examples/type_errors/missing_arguments.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
filter foo {
define {
rx msg: U32;
x = ["foo", "bar"];
b = x.contains(); // should error error: not enough arguments
}
}
11 changes: 11 additions & 0 deletions examples/type_errors/missing_data_field.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
filter foo {
define {
rx msg: BmpMessage;
}

term bar {
match msg with {
InitiationMessage -> true, // should error here
}
}
}
10 changes: 10 additions & 0 deletions examples/type_errors/missing_fields.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Foo { a: U32, b: U32, c: U32 }

filter foo {
define {
rx msg: U32;
a = Foo {
a: 8,
}; // should error here
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/no_such_static_method.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: U32;
a = String.i_do_not_exist();
}
}
7 changes: 7 additions & 0 deletions examples/type_errors/overriding_builtin.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type U32 { b: U32 } // should error here

filter foo {
define {
rx msg: U32;
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/record_literal_on_non_record.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: U32;
a = String { a: 8 };
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/standalone_type.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: U32;
a = String;
}
}
5 changes: 5 additions & 0 deletions examples/type_errors/type_not_found.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filter foo {
define {
rx msg: FOO;
}
}
8 changes: 8 additions & 0 deletions examples/type_errors/types_with_the_same_name.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Foo { a: U32 }
type Foo { b: U32 } // should error here

filter foo {
define {
rx msg: U32;
}
}
6 changes: 6 additions & 0 deletions examples/type_errors/undefined_variable.roto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filter foo {
define {
rx msg: BmpMessage;
a = b; // error: undefined variable
}
}
Loading
Loading