mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
use pattern in FromAnnotation
so we can also annotate non-identifier patterns.
This commit is contained in:
parent
307b19bd2c
commit
cbca93b030
2 changed files with 9 additions and 24 deletions
|
@ -457,14 +457,8 @@ fn canonicalize_def<'a>(
|
||||||
// TODO remove this clone
|
// TODO remove this clone
|
||||||
*found_rigids = found_rigids.clone().union(ftv_sendmap);
|
*found_rigids = found_rigids.clone().union(ftv_sendmap);
|
||||||
|
|
||||||
let fname: String = if let Pattern::Identifier(_, name) = loc_can_pattern.value {
|
|
||||||
(Into::<Box<str>>::into(name)).to_string()
|
|
||||||
} else {
|
|
||||||
panic!("TODO support other patterns too (requires changing FromAnnotation)");
|
|
||||||
};
|
|
||||||
|
|
||||||
let annotation_expected = FromAnnotation(
|
let annotation_expected = FromAnnotation(
|
||||||
fname,
|
loc_can_pattern,
|
||||||
can_annotation.arity(),
|
can_annotation.arity(),
|
||||||
AnnotationSource::TypedBody,
|
AnnotationSource::TypedBody,
|
||||||
can_annotation,
|
can_annotation,
|
||||||
|
@ -503,19 +497,9 @@ fn canonicalize_def<'a>(
|
||||||
// identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called.
|
// identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called.
|
||||||
let outer_identifier = env.tailcallable_symbol.clone();
|
let outer_identifier = env.tailcallable_symbol.clone();
|
||||||
|
|
||||||
// TODO ensure TypedDef has a pattern identifier?
|
if let (&ast::Pattern::Identifier(_), &Pattern::Identifier(_, ref defined_symbol)) =
|
||||||
// e.g. in elm, you can't type
|
(&loc_pattern.value, &loc_can_pattern.value)
|
||||||
//
|
|
||||||
// (foo, bar) : (Int, Bool)
|
|
||||||
// implicitly, that is the case here too
|
|
||||||
let mut fname = "invalid name".to_string();
|
|
||||||
|
|
||||||
if let (
|
|
||||||
&ast::Pattern::Identifier(ref name),
|
|
||||||
&Pattern::Identifier(_, ref defined_symbol),
|
|
||||||
) = (&loc_pattern.value, &loc_can_pattern.value)
|
|
||||||
{
|
{
|
||||||
fname = (*name).to_string();
|
|
||||||
env.tailcallable_symbol = Some(defined_symbol.clone());
|
env.tailcallable_symbol = Some(defined_symbol.clone());
|
||||||
variables_by_symbol.insert(defined_symbol.clone(), expr_var);
|
variables_by_symbol.insert(defined_symbol.clone(), expr_var);
|
||||||
};
|
};
|
||||||
|
@ -535,7 +519,7 @@ fn canonicalize_def<'a>(
|
||||||
let new_rtv = rigids.clone().union(new_rigids);
|
let new_rtv = rigids.clone().union(new_rigids);
|
||||||
|
|
||||||
let annotation_expected = FromAnnotation(
|
let annotation_expected = FromAnnotation(
|
||||||
fname,
|
loc_can_pattern.clone(),
|
||||||
can_annotation.arity(),
|
can_annotation.arity(),
|
||||||
AnnotationSource::TypedBody,
|
AnnotationSource::TypedBody,
|
||||||
can_annotation,
|
can_annotation,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::can::ident::{Lowercase, ModuleName, Uppercase};
|
use crate::can::ident::{Lowercase, ModuleName, Uppercase};
|
||||||
|
use crate::can::pattern::Pattern;
|
||||||
use crate::can::symbol::Symbol;
|
use crate::can::symbol::Symbol;
|
||||||
use crate::collections::{MutSet, SendMap};
|
use crate::collections::{MutSet, SendMap};
|
||||||
use crate::operator::{ArgSide, BinOp};
|
use crate::operator::{ArgSide, BinOp};
|
||||||
|
@ -189,10 +190,10 @@ impl Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Expected<T> {
|
pub enum Expected<T> {
|
||||||
NoExpectation(T),
|
NoExpectation(T),
|
||||||
FromAnnotation(String, usize, AnnotationSource, T),
|
FromAnnotation(Located<Pattern>, usize, AnnotationSource, T),
|
||||||
ForReason(Reason, T, Region),
|
ForReason(Reason, T, Region),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +254,7 @@ pub enum Reason {
|
||||||
ElemInList,
|
ElemInList,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum Constraint {
|
pub enum Constraint {
|
||||||
Eq(Type, Expected<Type>, Region),
|
Eq(Type, Expected<Type>, Region),
|
||||||
|
@ -277,7 +278,7 @@ pub enum PatternCategory {
|
||||||
Float,
|
Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct LetConstraint {
|
pub struct LetConstraint {
|
||||||
pub rigid_vars: Vec<Variable>,
|
pub rigid_vars: Vec<Variable>,
|
||||||
pub flex_vars: Vec<Variable>,
|
pub flex_vars: Vec<Variable>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue