From fe85af8d037323d3becee18fa3a4e37cd52be325 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sun, 21 Nov 2021 21:37:34 -0500 Subject: [PATCH] Fix failing compilation in Expr2 --- ast/src/constrain.rs | 33 ++++++++++++++++++++++-------- ast/src/mem_pool/shallow_clone.rs | 9 ++++++-- ast/src/solve_type.rs | 2 +- compiler/can/src/annotation.rs | 13 +++++++++++- compiler/load/src/effect_module.rs | 4 ++++ 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 2172797cc8..2fcc3de67c 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -6,7 +6,7 @@ use roc_module::{ ident::{Lowercase, TagName}, symbol::Symbol, }; -use roc_region::all::Region; +use roc_region::all::{Located, Region}; use roc_types::{ subs::Variable, types::{self, AnnotationSource, PReason, PatternCategory}, @@ -32,9 +32,9 @@ use crate::{ #[derive(Debug)] pub enum Constraint<'a> { - Eq(Type2, Expected, Category, Region), + Eq(Type2, Expected, Category, Region), // Store(Type, Variable, &'static str, u32), - Lookup(Symbol, Expected, Region), + Lookup(Symbol, Expected, Region), Pattern(Region, PatternCategory, Type2, PExpected), And(BumpVec<'a, Constraint<'a>>), Let(&'a LetConstraint<'a>), @@ -55,7 +55,7 @@ pub fn constrain_expr<'a>( arena: &'a Bump, env: &mut Env, expr: &Expr2, - expected: Expected, + expected: Expected, region: Region, ) -> Constraint<'a> { use Constraint::*; @@ -506,7 +506,7 @@ pub fn constrain_expr<'a>( flex_vars.push(*expr_var); match expected { - Expected::FromAnnotation(name, arity, _, tipe) => { + Expected::FromAnnotation(name, arity, ann_source, tipe) => { let num_branches = branches.len() + 1; for (index, branch_id) in branches.iter_node_ids().enumerate() { @@ -528,6 +528,10 @@ pub fn constrain_expr<'a>( AnnotationSource::TypedIfBranch { index: Index::zero_based(index), num_branches, + annotation: Located::at( + ann_source.region(), + ann_source.annotation().value, + ), }, tipe.shallow_clone(), ), @@ -548,6 +552,10 @@ pub fn constrain_expr<'a>( AnnotationSource::TypedIfBranch { index: Index::zero_based(branches.len()), num_branches, + annotation: Located::at( + ann_source.region(), + ann_source.annotation().value, + ), }, tipe.shallow_clone(), ), @@ -654,7 +662,7 @@ pub fn constrain_expr<'a>( flex_vars.push(*expr_var); match &expected { - Expected::FromAnnotation(name, arity, _, _typ) => { + Expected::FromAnnotation(name, arity, ann_source, _typ) => { // NOTE deviation from elm. // // in elm, `_typ` is used, but because we have this `expr_var` too @@ -687,6 +695,10 @@ pub fn constrain_expr<'a>( *arity, AnnotationSource::TypedWhenBranch { index: Index::zero_based(index), + annotation: Located::at( + ann_source.region(), + ann_source.annotation().value, + ), }, typ.shallow_clone(), ), @@ -1173,7 +1185,7 @@ fn exists<'a>( fn constrain_tag<'a>( arena: &'a Bump, env: &mut Env, - expected: Expected, + expected: Expected, region: Region, tag_name: TagName, arguments: &PoolVec<(Variable, ExprId)>, @@ -1263,7 +1275,10 @@ fn constrain_field_update<'a>( (field_type, con) } -fn constrain_empty_record<'a>(expected: Expected, region: Region) -> Constraint<'a> { +fn constrain_empty_record<'a>( + expected: Expected, + region: Region, +) -> Constraint<'a> { Constraint::Eq(Type2::EmptyRec, expected, Category::Record, region) } @@ -1274,7 +1289,7 @@ fn constrain_when_branch<'a>( region: Region, when_branch: &WhenBranch, pattern_expected: PExpected, - expr_expected: Expected, + expr_expected: Expected, ) -> Constraint<'a> { let when_expr = env.pool.get(when_branch.body); diff --git a/ast/src/mem_pool/shallow_clone.rs b/ast/src/mem_pool/shallow_clone.rs index f444b1f897..b1c3b172b2 100644 --- a/ast/src/mem_pool/shallow_clone.rs +++ b/ast/src/mem_pool/shallow_clone.rs @@ -1,12 +1,17 @@ use roc_can::expected::Expected; use roc_can::expected::PExpected; +use roc_types::subs::Variable; /// Clones the outer node, but does not clone any nodeids pub trait ShallowClone { fn shallow_clone(&self) -> Self; } -impl ShallowClone for Expected { +impl ShallowClone for Expected +where + T: ShallowClone, + Annot: Clone, +{ fn shallow_clone(&self) -> Self { use Expected::*; @@ -14,7 +19,7 @@ impl ShallowClone for Expected { NoExpectation(t) => NoExpectation(t.shallow_clone()), ForReason(reason, t, region) => ForReason(reason.clone(), t.shallow_clone(), *region), FromAnnotation(loc_pat, n, source, t) => { - FromAnnotation(loc_pat.clone(), *n, *source, t.shallow_clone()) + FromAnnotation(loc_pat.clone(), *n, source.clone(), t.shallow_clone()) } } } diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index ce63419a56..7627d86f92 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -75,7 +75,7 @@ use crate::mem_pool::shallow_clone::ShallowClone; #[derive(PartialEq, Debug, Clone)] pub enum TypeError { - BadExpr(Region, Category, ErrorType, Expected), + BadExpr(Region, Category, ErrorType, Expected), BadPattern(Region, PatternCategory, ErrorType, PExpected), CircularType(Region, Symbol, ErrorType), BadType(roc_types::types::Problem), diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index a0e4841560..0c9e202cd7 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -386,7 +386,18 @@ fn can_annotation_help( } }, - Record { fields, ext, .. } => { + Record { fields, ext } => { + let field_types = can_assigned_fields( + env, + &fields.items, + region, + scope, + var_store, + introduced_variables, + local_aliases, + references, + ); + let ext_type = match ext { Some(loc_ann) => can_annotation_help( env, diff --git a/compiler/load/src/effect_module.rs b/compiler/load/src/effect_module.rs index 24f46cda44..10f07b5307 100644 --- a/compiler/load/src/effect_module.rs +++ b/compiler/load/src/effect_module.rs @@ -191,6 +191,7 @@ fn build_effect_always( let def_annotation = roc_can::def::Annotation { signature, introduced_variables, + annotation_var: var_store.fresh(), aliases: SendMap::default(), region: Region::zero(), }; @@ -403,6 +404,7 @@ fn build_effect_map( let def_annotation = roc_can::def::Annotation { signature, introduced_variables, + annotation_var: var_store.fresh(), aliases: SendMap::default(), region: Region::zero(), }; @@ -570,6 +572,7 @@ fn build_effect_after( let def_annotation = roc_can::def::Annotation { signature, introduced_variables, + annotation_var: var_store.fresh(), aliases: SendMap::default(), region: Region::zero(), }; @@ -742,6 +745,7 @@ pub fn build_host_exposed_def( let def_annotation = roc_can::def::Annotation { signature: annotation.typ, introduced_variables: annotation.introduced_variables, + annotation_var: var_store.fresh(), aliases: annotation.aliases, region: Region::zero(), };