mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Fix failing compilation in Expr2
This commit is contained in:
parent
3b7596dd34
commit
fe85af8d03
5 changed files with 48 additions and 13 deletions
|
@ -6,7 +6,7 @@ use roc_module::{
|
||||||
ident::{Lowercase, TagName},
|
ident::{Lowercase, TagName},
|
||||||
symbol::Symbol,
|
symbol::Symbol,
|
||||||
};
|
};
|
||||||
use roc_region::all::Region;
|
use roc_region::all::{Located, Region};
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
subs::Variable,
|
subs::Variable,
|
||||||
types::{self, AnnotationSource, PReason, PatternCategory},
|
types::{self, AnnotationSource, PReason, PatternCategory},
|
||||||
|
@ -32,9 +32,9 @@ use crate::{
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Constraint<'a> {
|
pub enum Constraint<'a> {
|
||||||
Eq(Type2, Expected<Type2>, Category, Region),
|
Eq(Type2, Expected<Type2, Variable>, Category, Region),
|
||||||
// Store(Type, Variable, &'static str, u32),
|
// Store(Type, Variable, &'static str, u32),
|
||||||
Lookup(Symbol, Expected<Type2>, Region),
|
Lookup(Symbol, Expected<Type2, Variable>, Region),
|
||||||
Pattern(Region, PatternCategory, Type2, PExpected<Type2>),
|
Pattern(Region, PatternCategory, Type2, PExpected<Type2>),
|
||||||
And(BumpVec<'a, Constraint<'a>>),
|
And(BumpVec<'a, Constraint<'a>>),
|
||||||
Let(&'a LetConstraint<'a>),
|
Let(&'a LetConstraint<'a>),
|
||||||
|
@ -55,7 +55,7 @@ pub fn constrain_expr<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
expr: &Expr2,
|
expr: &Expr2,
|
||||||
expected: Expected<Type2>,
|
expected: Expected<Type2, Variable>,
|
||||||
region: Region,
|
region: Region,
|
||||||
) -> Constraint<'a> {
|
) -> Constraint<'a> {
|
||||||
use Constraint::*;
|
use Constraint::*;
|
||||||
|
@ -506,7 +506,7 @@ pub fn constrain_expr<'a>(
|
||||||
flex_vars.push(*expr_var);
|
flex_vars.push(*expr_var);
|
||||||
|
|
||||||
match expected {
|
match expected {
|
||||||
Expected::FromAnnotation(name, arity, _, tipe) => {
|
Expected::FromAnnotation(name, arity, ann_source, tipe) => {
|
||||||
let num_branches = branches.len() + 1;
|
let num_branches = branches.len() + 1;
|
||||||
|
|
||||||
for (index, branch_id) in branches.iter_node_ids().enumerate() {
|
for (index, branch_id) in branches.iter_node_ids().enumerate() {
|
||||||
|
@ -528,6 +528,10 @@ pub fn constrain_expr<'a>(
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(index),
|
index: Index::zero_based(index),
|
||||||
num_branches,
|
num_branches,
|
||||||
|
annotation: Located::at(
|
||||||
|
ann_source.region(),
|
||||||
|
ann_source.annotation().value,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
tipe.shallow_clone(),
|
tipe.shallow_clone(),
|
||||||
),
|
),
|
||||||
|
@ -548,6 +552,10 @@ pub fn constrain_expr<'a>(
|
||||||
AnnotationSource::TypedIfBranch {
|
AnnotationSource::TypedIfBranch {
|
||||||
index: Index::zero_based(branches.len()),
|
index: Index::zero_based(branches.len()),
|
||||||
num_branches,
|
num_branches,
|
||||||
|
annotation: Located::at(
|
||||||
|
ann_source.region(),
|
||||||
|
ann_source.annotation().value,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
tipe.shallow_clone(),
|
tipe.shallow_clone(),
|
||||||
),
|
),
|
||||||
|
@ -654,7 +662,7 @@ pub fn constrain_expr<'a>(
|
||||||
flex_vars.push(*expr_var);
|
flex_vars.push(*expr_var);
|
||||||
|
|
||||||
match &expected {
|
match &expected {
|
||||||
Expected::FromAnnotation(name, arity, _, _typ) => {
|
Expected::FromAnnotation(name, arity, ann_source, _typ) => {
|
||||||
// NOTE deviation from elm.
|
// NOTE deviation from elm.
|
||||||
//
|
//
|
||||||
// in elm, `_typ` is used, but because we have this `expr_var` too
|
// in elm, `_typ` is used, but because we have this `expr_var` too
|
||||||
|
@ -687,6 +695,10 @@ pub fn constrain_expr<'a>(
|
||||||
*arity,
|
*arity,
|
||||||
AnnotationSource::TypedWhenBranch {
|
AnnotationSource::TypedWhenBranch {
|
||||||
index: Index::zero_based(index),
|
index: Index::zero_based(index),
|
||||||
|
annotation: Located::at(
|
||||||
|
ann_source.region(),
|
||||||
|
ann_source.annotation().value,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
typ.shallow_clone(),
|
typ.shallow_clone(),
|
||||||
),
|
),
|
||||||
|
@ -1173,7 +1185,7 @@ fn exists<'a>(
|
||||||
fn constrain_tag<'a>(
|
fn constrain_tag<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
expected: Expected<Type2>,
|
expected: Expected<Type2, Variable>,
|
||||||
region: Region,
|
region: Region,
|
||||||
tag_name: TagName,
|
tag_name: TagName,
|
||||||
arguments: &PoolVec<(Variable, ExprId)>,
|
arguments: &PoolVec<(Variable, ExprId)>,
|
||||||
|
@ -1263,7 +1275,10 @@ fn constrain_field_update<'a>(
|
||||||
(field_type, con)
|
(field_type, con)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constrain_empty_record<'a>(expected: Expected<Type2>, region: Region) -> Constraint<'a> {
|
fn constrain_empty_record<'a>(
|
||||||
|
expected: Expected<Type2, Variable>,
|
||||||
|
region: Region,
|
||||||
|
) -> Constraint<'a> {
|
||||||
Constraint::Eq(Type2::EmptyRec, expected, Category::Record, region)
|
Constraint::Eq(Type2::EmptyRec, expected, Category::Record, region)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1274,7 +1289,7 @@ fn constrain_when_branch<'a>(
|
||||||
region: Region,
|
region: Region,
|
||||||
when_branch: &WhenBranch,
|
when_branch: &WhenBranch,
|
||||||
pattern_expected: PExpected<Type2>,
|
pattern_expected: PExpected<Type2>,
|
||||||
expr_expected: Expected<Type2>,
|
expr_expected: Expected<Type2, Variable>,
|
||||||
) -> Constraint<'a> {
|
) -> Constraint<'a> {
|
||||||
let when_expr = env.pool.get(when_branch.body);
|
let when_expr = env.pool.get(when_branch.body);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
use roc_can::expected::Expected;
|
use roc_can::expected::Expected;
|
||||||
use roc_can::expected::PExpected;
|
use roc_can::expected::PExpected;
|
||||||
|
use roc_types::subs::Variable;
|
||||||
|
|
||||||
/// Clones the outer node, but does not clone any nodeids
|
/// Clones the outer node, but does not clone any nodeids
|
||||||
pub trait ShallowClone {
|
pub trait ShallowClone {
|
||||||
fn shallow_clone(&self) -> Self;
|
fn shallow_clone(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ShallowClone> ShallowClone for Expected<T> {
|
impl<T, Annot> ShallowClone for Expected<T, Annot>
|
||||||
|
where
|
||||||
|
T: ShallowClone,
|
||||||
|
Annot: Clone,
|
||||||
|
{
|
||||||
fn shallow_clone(&self) -> Self {
|
fn shallow_clone(&self) -> Self {
|
||||||
use Expected::*;
|
use Expected::*;
|
||||||
|
|
||||||
|
@ -14,7 +19,7 @@ impl<T: ShallowClone> ShallowClone for Expected<T> {
|
||||||
NoExpectation(t) => NoExpectation(t.shallow_clone()),
|
NoExpectation(t) => NoExpectation(t.shallow_clone()),
|
||||||
ForReason(reason, t, region) => ForReason(reason.clone(), t.shallow_clone(), *region),
|
ForReason(reason, t, region) => ForReason(reason.clone(), t.shallow_clone(), *region),
|
||||||
FromAnnotation(loc_pat, n, source, t) => {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ use crate::mem_pool::shallow_clone::ShallowClone;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
pub enum TypeError {
|
pub enum TypeError {
|
||||||
BadExpr(Region, Category, ErrorType, Expected<ErrorType>),
|
BadExpr(Region, Category, ErrorType, Expected<ErrorType, Variable>),
|
||||||
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),
|
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),
|
||||||
CircularType(Region, Symbol, ErrorType),
|
CircularType(Region, Symbol, ErrorType),
|
||||||
BadType(roc_types::types::Problem),
|
BadType(roc_types::types::Problem),
|
||||||
|
|
|
@ -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 {
|
let ext_type = match ext {
|
||||||
Some(loc_ann) => can_annotation_help(
|
Some(loc_ann) => can_annotation_help(
|
||||||
env,
|
env,
|
||||||
|
|
|
@ -191,6 +191,7 @@ fn build_effect_always(
|
||||||
let def_annotation = roc_can::def::Annotation {
|
let def_annotation = roc_can::def::Annotation {
|
||||||
signature,
|
signature,
|
||||||
introduced_variables,
|
introduced_variables,
|
||||||
|
annotation_var: var_store.fresh(),
|
||||||
aliases: SendMap::default(),
|
aliases: SendMap::default(),
|
||||||
region: Region::zero(),
|
region: Region::zero(),
|
||||||
};
|
};
|
||||||
|
@ -403,6 +404,7 @@ fn build_effect_map(
|
||||||
let def_annotation = roc_can::def::Annotation {
|
let def_annotation = roc_can::def::Annotation {
|
||||||
signature,
|
signature,
|
||||||
introduced_variables,
|
introduced_variables,
|
||||||
|
annotation_var: var_store.fresh(),
|
||||||
aliases: SendMap::default(),
|
aliases: SendMap::default(),
|
||||||
region: Region::zero(),
|
region: Region::zero(),
|
||||||
};
|
};
|
||||||
|
@ -570,6 +572,7 @@ fn build_effect_after(
|
||||||
let def_annotation = roc_can::def::Annotation {
|
let def_annotation = roc_can::def::Annotation {
|
||||||
signature,
|
signature,
|
||||||
introduced_variables,
|
introduced_variables,
|
||||||
|
annotation_var: var_store.fresh(),
|
||||||
aliases: SendMap::default(),
|
aliases: SendMap::default(),
|
||||||
region: Region::zero(),
|
region: Region::zero(),
|
||||||
};
|
};
|
||||||
|
@ -742,6 +745,7 @@ pub fn build_host_exposed_def(
|
||||||
let def_annotation = roc_can::def::Annotation {
|
let def_annotation = roc_can::def::Annotation {
|
||||||
signature: annotation.typ,
|
signature: annotation.typ,
|
||||||
introduced_variables: annotation.introduced_variables,
|
introduced_variables: annotation.introduced_variables,
|
||||||
|
annotation_var: var_store.fresh(),
|
||||||
aliases: annotation.aliases,
|
aliases: annotation.aliases,
|
||||||
region: Region::zero(),
|
region: Region::zero(),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue