From 30c31330d55494fd8b05ed03297c98e8283339ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20D=C3=B6nszelmann?= Date: Mon, 27 May 2024 22:04:42 +0200 Subject: [PATCH] fix duplicate definition test --- scopegraphs/examples/records/ast.rs | 8 ++--- scopegraphs/examples/records/main.rs | 2 +- scopegraphs/examples/records/parse.rs | 7 ++--- scopegraphs/examples/records/tests.rs | 44 --------------------------- 4 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 scopegraphs/examples/records/tests.rs diff --git a/scopegraphs/examples/records/ast.rs b/scopegraphs/examples/records/ast.rs index 173b23d..aa4d795 100644 --- a/scopegraphs/examples/records/ast.rs +++ b/scopegraphs/examples/records/ast.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - #[derive(Debug, Clone, PartialEq, Eq)] pub enum Type { StructRef(String), @@ -9,14 +7,14 @@ pub enum Type { #[derive(Debug)] pub struct RecordDef { pub name: String, - pub fields: HashMap, + pub fields: Vec<(String, Type)>, } #[derive(Debug, Clone)] pub enum Expr { StructInit { name: String, - fields: HashMap, + fields: Vec<(String, Expr)>, }, #[allow(unused)] Add(Box, Box), @@ -30,7 +28,7 @@ pub enum Expr { in_expr: Box, }, LetRec { - values: HashMap, + values: Vec<(String, Expr)>, in_expr: Box, }, } diff --git a/scopegraphs/examples/records/main.rs b/scopegraphs/examples/records/main.rs index a4b0a74..cd9dfc5 100644 --- a/scopegraphs/examples/records/main.rs +++ b/scopegraphs/examples/records/main.rs @@ -392,7 +392,7 @@ mod tests { } #[test] - #[should_panic = "duplicate definition"] + #[should_panic = "variable did not resolve uniquely: OnlyElementError::Multiple {..}"] fn test_letrec_shadow() { test_example( "record A {} main = letrec a = new A {}; a = 42; in a;", diff --git a/scopegraphs/examples/records/parse.rs b/scopegraphs/examples/records/parse.rs index bfbecb5..03b959c 100644 --- a/scopegraphs/examples/records/parse.rs +++ b/scopegraphs/examples/records/parse.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use winnow::ascii::multispace0; use winnow::combinator::{alt, delimited, opt, preceded, repeat, separated, terminated}; use winnow::error::{ParserError, StrContext}; @@ -57,7 +56,7 @@ fn parse_field_def(input: &mut &'_ str) -> PResult<(String, Type)> { .parse_next(input) } -fn parse_field_defs(input: &mut &'_ str) -> PResult> { +fn parse_field_defs(input: &mut &'_ str) -> PResult> { terminated(separated(0.., ws(parse_field_def), ws(",")), opt(ws(","))).parse_next(input) } @@ -72,7 +71,7 @@ fn parse_field(input: &mut &'_ str) -> PResult<(String, Expr)> { .parse_next(input) } -fn parse_fields(input: &mut &'_ str) -> PResult> { +fn parse_fields(input: &mut &'_ str) -> PResult> { terminated(separated(0.., ws(parse_field), ws(",")), opt(ws(","))).parse_next(input) } @@ -97,7 +96,7 @@ fn parse_value(input: &mut &'_ str) -> PResult<(String, Expr)> { .parse_next(input) } -fn parse_values(input: &mut &'_ str) -> PResult> { +fn parse_values(input: &mut &'_ str) -> PResult> { repeat(0.., parse_value).parse_next(input) } diff --git a/scopegraphs/examples/records/tests.rs b/scopegraphs/examples/records/tests.rs deleted file mode 100644 index 883c6f2..0000000 --- a/scopegraphs/examples/records/tests.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::{ast, parse::parse, typecheck}; - -fn test_example(program: &str, expected_main_type: ast::Type) { - let ast = parse(program).expect("parse failure"); - let ty = typecheck(&ast).expect("type not instantiated"); - assert_eq!(ty, expected_main_type) -} - -#[test] -fn test_integer() { - test_example("main = 42;", ast::Type::Int) -} - -#[test] -fn test_letrec() { - test_example("main = letrec a = 42; in a;", ast::Type::Int) -} - -#[test] -fn test_let() { - test_example("main = let a = 42; in a;", ast::Type::Int) -} - -#[test] -fn test_complex() { - test_example( - " -record A { - b: B, - x: int, -} -record B { - a: A, - x: int, -} - -main = letrec - a = new A {x: 4, b: b}; - b = new B {x: 3, a: a}; -in a.b.a.x; - ", - ast::Type::Int, - ) -}