use pattern in FromAnnotation

so we can also annotate non-identifier patterns.
This commit is contained in:
Folkert 2019-12-20 15:41:42 +01:00
parent 307b19bd2c
commit cbca93b030
2 changed files with 9 additions and 24 deletions

View file

@ -457,14 +457,8 @@ fn canonicalize_def<'a>(
// TODO remove this clone
*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(
fname,
loc_can_pattern,
can_annotation.arity(),
AnnotationSource::TypedBody,
can_annotation,
@ -503,19 +497,9 @@ fn canonicalize_def<'a>(
// identifier (e.g. `f = \x -> ...`), then this symbol can be tail-called.
let outer_identifier = env.tailcallable_symbol.clone();
// TODO ensure TypedDef has a pattern identifier?
// e.g. in elm, you can't type
//
// (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)
if let (&ast::Pattern::Identifier(_), &Pattern::Identifier(_, ref defined_symbol)) =
(&loc_pattern.value, &loc_can_pattern.value)
{
fname = (*name).to_string();
env.tailcallable_symbol = Some(defined_symbol.clone());
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 annotation_expected = FromAnnotation(
fname,
loc_can_pattern.clone(),
can_annotation.arity(),
AnnotationSource::TypedBody,
can_annotation,

View file

@ -1,4 +1,5 @@
use crate::can::ident::{Lowercase, ModuleName, Uppercase};
use crate::can::pattern::Pattern;
use crate::can::symbol::Symbol;
use crate::collections::{MutSet, SendMap};
use crate::operator::{ArgSide, BinOp};
@ -189,10 +190,10 @@ impl Type {
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub enum Expected<T> {
NoExpectation(T),
FromAnnotation(String, usize, AnnotationSource, T),
FromAnnotation(Located<Pattern>, usize, AnnotationSource, T),
ForReason(Reason, T, Region),
}
@ -253,7 +254,7 @@ pub enum Reason {
ElemInList,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum Constraint {
Eq(Type, Expected<Type>, Region),
@ -277,7 +278,7 @@ pub enum PatternCategory {
Float,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub struct LetConstraint {
pub rigid_vars: Vec<Variable>,
pub flex_vars: Vec<Variable>,