From 5b137e0983051bf72759cea9c4af1c4bc7a24e1f Mon Sep 17 00:00:00 2001 From: David Li Date: Mon, 6 Nov 2017 09:26:23 -0500 Subject: Type check record definitions --- src/ast.rs | 4 ++-- src/semantic/translate.rs | 15 +++++++-------- src/taiga.lalrpop | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ast.rs b/src/ast.rs index 3cc68c1..744397a 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -86,11 +86,11 @@ pub enum Expression { #[derive(Debug)] pub struct RecordField { pub name: WithLocation, - pub ty: WithLocation, + pub ty: WithLocation, } impl RecordField { - pub fn new(name: WithLocation, ty: WithLocation) -> RecordField { + pub fn new(name: WithLocation, ty: WithLocation) -> RecordField { RecordField { name, ty } } } diff --git a/src/semantic/translate.rs b/src/semantic/translate.rs index 6c7f60c..dfcec68 100644 --- a/src/semantic/translate.rs +++ b/src/semantic/translate.rs @@ -43,14 +43,13 @@ fn trans_ty<'a>( trans_ty(venv, tenv, &inner_ty) }, ast::Ty::Record(ref fields) => { - err!(ty, TypeError::Unimplemented) - // let result = vec![]; - // for field in fields { - // result.push(types::RecordField::new( - // *field.name, - // trans_ty(venv, tenv, field.ty)?)); - // } - // Ok(Ty::Record(result)) + let mut result = vec![]; + for field in fields { + result.push(types::RecordField::new( + field.name.clone(), + trans_ty(venv, tenv, &field.ty)?)); + } + Ok(Ty::Record(result)) }, } } diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop index 0c7fea0..bad60bb 100644 --- a/src/taiga.lalrpop +++ b/src/taiga.lalrpop @@ -8,13 +8,13 @@ pub Program: ast::Program = { }; FieldList: Vec> = { - ":" "," => { + ":" "," => { let mut rest = rest; rest.push(WithLocation::new(ast::RecordField::new(n, v), l, r)); rest }, - ":" "," => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], - ":" => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], + ":" "," => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], + ":" => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], }; RecordFields: WithLocation>> = { -- cgit v1.2.3