chore: assignment patterns refactor tuple into struct
This commit is contained in:
parent
b6b52ba508
commit
97247ce949
|
@ -1436,6 +1436,27 @@ impl Default for Bls12_381Point {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct AssignmentPattern {
|
||||||
|
pub pattern: UntypedPattern,
|
||||||
|
pub annotation: Option<Annotation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssignmentPattern {
|
||||||
|
pub fn new(pattern: UntypedPattern, annotation: Option<Annotation>) -> AssignmentPattern {
|
||||||
|
Self {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AssignmentPattern> for Vec1<AssignmentPattern> {
|
||||||
|
fn from(value: AssignmentPattern) -> Self {
|
||||||
|
Vec1::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type UntypedAssignmentKind = AssignmentKind<bool>;
|
pub type UntypedAssignmentKind = AssignmentKind<bool>;
|
||||||
pub type TypedAssignmentKind = AssignmentKind<()>;
|
pub type TypedAssignmentKind = AssignmentKind<()>;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
self, Annotation, Arg, ArgName, BinOp, Bls12_381Point, ByteArrayFormatPreference, CallArg,
|
self, Annotation, Arg, ArgName, AssignmentPattern, BinOp, Bls12_381Point,
|
||||||
Curve, DataType, DataTypeKey, DefinitionLocation, IfBranch, Located, LogicalOpChainKind,
|
ByteArrayFormatPreference, CallArg, Curve, DataType, DataTypeKey, DefinitionLocation,
|
||||||
ParsedCallArg, Pattern, RecordConstructorArg, RecordUpdateSpread, Span, TraceKind,
|
IfBranch, Located, LogicalOpChainKind, ParsedCallArg, Pattern, RecordConstructorArg,
|
||||||
TypedAssignmentKind, TypedClause, TypedDataType, TypedRecordUpdateArg, UnOp,
|
RecordUpdateSpread, Span, TraceKind, TypedAssignmentKind, TypedClause, TypedDataType,
|
||||||
UntypedAssignmentKind, UntypedClause, UntypedPattern, UntypedRecordUpdateArg,
|
TypedRecordUpdateArg, UnOp, UntypedAssignmentKind, UntypedClause, UntypedRecordUpdateArg,
|
||||||
},
|
},
|
||||||
builtins::void,
|
builtins::void,
|
||||||
parser::token::Base,
|
parser::token::Base,
|
||||||
|
@ -518,7 +518,7 @@ pub enum UntypedExpr {
|
||||||
Assignment {
|
Assignment {
|
||||||
location: Span,
|
location: Span,
|
||||||
value: Box<Self>,
|
value: Box<Self>,
|
||||||
patterns: Vec1<(UntypedPattern, Option<Annotation>)>,
|
patterns: Vec1<AssignmentPattern>,
|
||||||
kind: UntypedAssignmentKind,
|
kind: UntypedAssignmentKind,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
Annotation, Arg, ArgName, ArgVia, AssignmentKind, BinOp, ByteArrayFormatPreference,
|
Annotation, Arg, ArgName, ArgVia, AssignmentKind, AssignmentPattern, BinOp,
|
||||||
CallArg, ClauseGuard, Constant, CurveType, DataType, Definition, Function, IfBranch,
|
ByteArrayFormatPreference, CallArg, ClauseGuard, Constant, CurveType, DataType, Definition,
|
||||||
LogicalOpChainKind, ModuleConstant, Pattern, RecordConstructor, RecordConstructorArg,
|
Function, IfBranch, LogicalOpChainKind, ModuleConstant, Pattern, RecordConstructor,
|
||||||
RecordUpdateSpread, Span, TraceKind, TypeAlias, TypedArg, UnOp, UnqualifiedImport,
|
RecordConstructorArg, RecordUpdateSpread, Span, TraceKind, TypeAlias, TypedArg, UnOp,
|
||||||
UntypedArg, UntypedArgVia, UntypedAssignmentKind, UntypedClause, UntypedClauseGuard,
|
UnqualifiedImport, UntypedArg, UntypedArgVia, UntypedAssignmentKind, UntypedClause,
|
||||||
UntypedDefinition, UntypedFunction, UntypedModule, UntypedPattern, UntypedRecordUpdateArg,
|
UntypedClauseGuard, UntypedDefinition, UntypedFunction, UntypedModule, UntypedPattern,
|
||||||
Use, Validator, CAPTURE_VARIABLE,
|
UntypedRecordUpdateArg, Use, Validator, CAPTURE_VARIABLE,
|
||||||
},
|
},
|
||||||
docvec,
|
docvec,
|
||||||
expr::{FnStyle, UntypedExpr, DEFAULT_ERROR_STR, DEFAULT_TODO_STR},
|
expr::{FnStyle, UntypedExpr, DEFAULT_ERROR_STR, DEFAULT_TODO_STR},
|
||||||
|
@ -679,7 +679,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
|
|
||||||
fn assignment<'a>(
|
fn assignment<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
patterns: &'a Vec1<(UntypedPattern, Option<Annotation>)>,
|
patterns: &'a Vec1<AssignmentPattern>,
|
||||||
value: &'a UntypedExpr,
|
value: &'a UntypedExpr,
|
||||||
kind: UntypedAssignmentKind,
|
kind: UntypedAssignmentKind,
|
||||||
) -> Document<'a> {
|
) -> Document<'a> {
|
||||||
|
@ -691,12 +691,13 @@ impl<'comments> Formatter<'comments> {
|
||||||
let symbol = if kind.is_backpassing() { "<-" } else { "=" };
|
let symbol = if kind.is_backpassing() { "<-" } else { "=" };
|
||||||
|
|
||||||
match patterns.first() {
|
match patterns.first() {
|
||||||
(
|
AssignmentPattern {
|
||||||
|
pattern:
|
||||||
UntypedPattern::Constructor {
|
UntypedPattern::Constructor {
|
||||||
name, module: None, ..
|
name, module: None, ..
|
||||||
},
|
},
|
||||||
annotation,
|
annotation,
|
||||||
) if name == "True"
|
} if name == "True"
|
||||||
&& annotation.is_none()
|
&& annotation.is_none()
|
||||||
&& kind.is_expect()
|
&& kind.is_expect()
|
||||||
&& patterns.len() == 1 =>
|
&& patterns.len() == 1 =>
|
||||||
|
@ -704,7 +705,11 @@ impl<'comments> Formatter<'comments> {
|
||||||
keyword.to_doc().append(self.case_clause_value(value))
|
keyword.to_doc().append(self.case_clause_value(value))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let patterns = patterns.into_iter().map(|(pattern, annotation)| {
|
let patterns = patterns.into_iter().map(
|
||||||
|
|AssignmentPattern {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
}| {
|
||||||
self.pop_empty_lines(pattern.location().end);
|
self.pop_empty_lines(pattern.location().end);
|
||||||
|
|
||||||
let pattern = self.pattern(pattern);
|
let pattern = self.pattern(pattern);
|
||||||
|
@ -714,7 +719,8 @@ impl<'comments> Formatter<'comments> {
|
||||||
.map(|a| ": ".to_doc().append(self.annotation(a)));
|
.map(|a| ": ".to_doc().append(self.annotation(a)));
|
||||||
|
|
||||||
pattern.append(annotation).group()
|
pattern.append(annotation).group()
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
keyword
|
keyword
|
||||||
.to_doc()
|
.to_doc()
|
||||||
|
|
|
@ -15,8 +15,8 @@ Test(
|
||||||
name: "False",
|
name: "False",
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Constructor {
|
pattern: Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: 38..42,
|
location: 38..42,
|
||||||
name: "True",
|
name: "True",
|
||||||
|
@ -26,8 +26,8 @@ Test(
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Expect {
|
kind: Expect {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -26,13 +26,13 @@ Fn(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 17..18,
|
location: 17..18,
|
||||||
name: "x",
|
name: "x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -12,6 +12,10 @@ pub fn let_(
|
||||||
.ignore_then(
|
.ignore_then(
|
||||||
pattern()
|
pattern()
|
||||||
.then(just(Token::Colon).ignore_then(annotation()).or_not())
|
.then(just(Token::Colon).ignore_then(annotation()).or_not())
|
||||||
|
.map(|(pattern, annotation)| ast::AssignmentPattern {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
})
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
.at_least(1),
|
.at_least(1),
|
||||||
)
|
)
|
||||||
|
@ -44,6 +48,10 @@ pub fn expect(
|
||||||
.ignore_then(
|
.ignore_then(
|
||||||
pattern()
|
pattern()
|
||||||
.then(just(Token::Colon).ignore_then(annotation()).or_not())
|
.then(just(Token::Colon).ignore_then(annotation()).or_not())
|
||||||
|
.map(|(pattern, annotation)| ast::AssignmentPattern {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
})
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
.at_least(1)
|
.at_least(1)
|
||||||
.then(choice((just(Token::Equal), just(Token::LArrow))))
|
.then(choice((just(Token::Equal), just(Token::LArrow))))
|
||||||
|
@ -57,8 +65,8 @@ pub fn expect(
|
||||||
|
|
||||||
let (patterns, kind) = opt_pattern.unwrap_or_else(|| {
|
let (patterns, kind) = opt_pattern.unwrap_or_else(|| {
|
||||||
(
|
(
|
||||||
vec![(
|
vec![ast::AssignmentPattern {
|
||||||
ast::UntypedPattern::Constructor {
|
pattern: ast::UntypedPattern::Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: span,
|
location: span,
|
||||||
name: "True".to_string(),
|
name: "True".to_string(),
|
||||||
|
@ -68,8 +76,8 @@ pub fn expect(
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
)],
|
}],
|
||||||
Token::Equal,
|
Token::Equal,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,13 +17,13 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 16..17,
|
location: 16..17,
|
||||||
name: "x",
|
name: "x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -47,13 +47,13 @@ Assignment {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "b",
|
name: "b",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -13,8 +13,8 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Constructor {
|
pattern: Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: 7..14,
|
location: 7..14,
|
||||||
name: "Some",
|
name: "Some",
|
||||||
|
@ -33,8 +33,8 @@ Assignment {
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Expect {
|
kind: Expect {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -21,8 +21,8 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Constructor {
|
pattern: Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: 0..29,
|
location: 0..29,
|
||||||
name: "True",
|
name: "True",
|
||||||
|
@ -32,8 +32,8 @@ Assignment {
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Expect {
|
kind: Expect {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -17,13 +17,13 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 13..14,
|
location: 13..14,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -32,8 +32,8 @@ Assignment {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Constructor {
|
pattern: Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: 0..21,
|
location: 0..21,
|
||||||
name: "True",
|
name: "True",
|
||||||
|
@ -43,8 +43,8 @@ Assignment {
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Expect {
|
kind: Expect {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -17,13 +17,13 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 14..15,
|
location: 14..15,
|
||||||
name: "b",
|
name: "b",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -32,13 +32,13 @@ Assignment {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -17,13 +17,13 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 14..15,
|
location: 14..15,
|
||||||
name: "b",
|
name: "b",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -32,13 +32,13 @@ Assignment {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -17,13 +17,13 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 16..17,
|
location: 16..17,
|
||||||
name: "b",
|
name: "b",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -36,13 +36,13 @@ Assignment {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -12,8 +12,8 @@ Assignment {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Constructor {
|
pattern: Constructor {
|
||||||
is_record: false,
|
is_record: false,
|
||||||
location: 0..11,
|
location: 0..11,
|
||||||
name: "True",
|
name: "True",
|
||||||
|
@ -23,8 +23,8 @@ Assignment {
|
||||||
with_spread: false,
|
with_spread: false,
|
||||||
tipo: (),
|
tipo: (),
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Expect {
|
kind: Expect {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -28,13 +28,13 @@ Sequence {
|
||||||
location: 8..18,
|
location: 8..18,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "x",
|
name: "x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -118,13 +118,13 @@ Sequence {
|
||||||
return_annotation: None,
|
return_annotation: None,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 24..33,
|
location: 24..33,
|
||||||
name: "map_add_x",
|
name: "map_add_x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -15,13 +15,13 @@ Sequence {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 8..9,
|
location: 8..9,
|
||||||
name: "i",
|
name: "i",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -37,13 +37,13 @@ Sequence {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 28..29,
|
location: 28..29,
|
||||||
name: "j",
|
name: "j",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -63,13 +63,13 @@ Sequence {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 48..49,
|
location: 48..49,
|
||||||
name: "k",
|
name: "k",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -29,13 +29,13 @@ Assignment {
|
||||||
tail: None,
|
tail: None,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..9,
|
location: 4..9,
|
||||||
name: "thing",
|
name: "thing",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -41,13 +41,13 @@ Sequence {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..9,
|
location: 4..9,
|
||||||
name: "tuple",
|
name: "tuple",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -28,13 +28,13 @@ Sequence {
|
||||||
location: 8..15,
|
location: 8..15,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 4..5,
|
location: 4..5,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -86,13 +86,13 @@ When {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 55..62,
|
location: 55..62,
|
||||||
name: "amazing",
|
name: "amazing",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -20,13 +20,13 @@ Module {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 19..20,
|
location: 19..20,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -64,13 +64,13 @@ Module {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 56..57,
|
location: 56..57,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -119,13 +119,13 @@ Module {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 93..94,
|
location: 93..94,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
@ -170,13 +170,13 @@ Module {
|
||||||
location: 130..137,
|
location: 130..137,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 126..127,
|
location: 126..127,
|
||||||
name: "a",
|
name: "a",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -25,13 +25,13 @@ Module {
|
||||||
preferred_format: Utf8String,
|
preferred_format: Utf8String,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 17..18,
|
location: 17..18,
|
||||||
name: "x",
|
name: "x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -23,13 +23,13 @@ Module {
|
||||||
preferred_format: Utf8String,
|
preferred_format: Utf8String,
|
||||||
},
|
},
|
||||||
patterns: [
|
patterns: [
|
||||||
(
|
AssignmentPattern {
|
||||||
Var {
|
pattern: Var {
|
||||||
location: 17..18,
|
location: 17..18,
|
||||||
name: "x",
|
name: "x",
|
||||||
},
|
},
|
||||||
None,
|
annotation: None,
|
||||||
),
|
},
|
||||||
],
|
],
|
||||||
kind: Let {
|
kind: Let {
|
||||||
backpassing: false,
|
backpassing: false,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
self, Annotation, Arg, ArgName, AssignmentKind, BinOp, Bls12_381Point,
|
self, Annotation, Arg, ArgName, AssignmentKind, AssignmentPattern, BinOp, Bls12_381Point,
|
||||||
ByteArrayFormatPreference, CallArg, ClauseGuard, Constant, Curve, IfBranch,
|
ByteArrayFormatPreference, CallArg, ClauseGuard, Constant, Curve, IfBranch,
|
||||||
LogicalOpChainKind, Pattern, RecordUpdateSpread, Span, TraceKind, TraceLevel, Tracing,
|
LogicalOpChainKind, Pattern, RecordUpdateSpread, Span, TraceKind, TraceLevel, Tracing,
|
||||||
TypedArg, TypedCallArg, TypedClause, TypedClauseGuard, TypedIfBranch, TypedPattern,
|
TypedArg, TypedCallArg, TypedClause, TypedClauseGuard, TypedIfBranch, TypedPattern,
|
||||||
|
@ -269,7 +269,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
} => {
|
} => {
|
||||||
// at this point due to backpassing rewrites,
|
// at this point due to backpassing rewrites,
|
||||||
// patterns is guaranteed to have one item
|
// patterns is guaranteed to have one item
|
||||||
let (pattern, annotation) = patterns.into_vec().swap_remove(0);
|
let AssignmentPattern {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
} = patterns.into_vec().swap_remove(0);
|
||||||
|
|
||||||
self.infer_assignment(pattern, *value, kind, &annotation, location)
|
self.infer_assignment(pattern, *value, kind, &annotation, location)
|
||||||
}
|
}
|
||||||
|
@ -966,7 +969,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
value: UntypedExpr::Assignment {
|
value: UntypedExpr::Assignment {
|
||||||
location,
|
location,
|
||||||
value: untyped_value.into(),
|
value: untyped_value.into(),
|
||||||
patterns: Vec1::new((untyped_pattern, Some(ann))),
|
patterns: AssignmentPattern::new(untyped_pattern, Some(ann)).into(),
|
||||||
kind,
|
kind,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1013,14 +1016,15 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
name: "...".to_string(),
|
name: "...".to_string(),
|
||||||
location: Span::empty(),
|
location: Span::empty(),
|
||||||
}),
|
}),
|
||||||
patterns: Vec1::new((untyped_pattern, None)),
|
patterns: AssignmentPattern::new(untyped_pattern, None)
|
||||||
|
.into(),
|
||||||
kind: AssignmentKind::Let { backpassing: true },
|
kind: AssignmentKind::Let { backpassing: true },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => UntypedExpr::Assignment {
|
_ => UntypedExpr::Assignment {
|
||||||
location: Span::empty(),
|
location: Span::empty(),
|
||||||
value: Box::new(untyped_value),
|
value: Box::new(untyped_value),
|
||||||
patterns: Vec1::new((untyped_pattern, None)),
|
patterns: AssignmentPattern::new(untyped_pattern, None).into(),
|
||||||
kind: AssignmentKind::let_(),
|
kind: AssignmentKind::let_(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1753,7 +1757,12 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
|
|
||||||
let mut names = Vec::new();
|
let mut names = Vec::new();
|
||||||
|
|
||||||
for (index, (pattern, annotation)) in patterns.into_iter().enumerate() {
|
for (index, assignment_pattern) in patterns.into_iter().enumerate() {
|
||||||
|
let AssignmentPattern {
|
||||||
|
pattern,
|
||||||
|
annotation,
|
||||||
|
} = assignment_pattern;
|
||||||
|
|
||||||
// In case where we have a Pattern that isn't simply a let-binding to a name, we do insert an extra let-binding
|
// In case where we have a Pattern that isn't simply a let-binding to a name, we do insert an extra let-binding
|
||||||
// in front of the continuation sequence. This is because we do not support patterns in function argument
|
// in front of the continuation sequence. This is because we do not support patterns in function argument
|
||||||
// (which is perhaps something we should support?).
|
// (which is perhaps something we should support?).
|
||||||
|
@ -1773,7 +1782,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
patterns: Vec1::new((pattern, annotation)),
|
patterns: AssignmentPattern::new(pattern, annotation).into(),
|
||||||
// erase backpassing while preserving assignment kind.
|
// erase backpassing while preserving assignment kind.
|
||||||
kind: match kind {
|
kind: match kind {
|
||||||
AssignmentKind::Let { .. } => AssignmentKind::let_(),
|
AssignmentKind::Let { .. } => AssignmentKind::let_(),
|
||||||
|
@ -1878,12 +1887,12 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
return Err(Error::UnexpectedMultiPatternAssignment {
|
return Err(Error::UnexpectedMultiPatternAssignment {
|
||||||
arrow: patterns
|
arrow: patterns
|
||||||
.last()
|
.last()
|
||||||
.0
|
.pattern
|
||||||
.location()
|
.location()
|
||||||
.map(|_, c_end| (c_end + 1, c_end + 1)),
|
.map(|_, c_end| (c_end + 1, c_end + 1)),
|
||||||
location: patterns[1..]
|
location: patterns[1..]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(p, _)| p.location())
|
.map(|ap| ap.pattern.location())
|
||||||
.reduce(|acc, loc| acc.union(loc))
|
.reduce(|acc, loc| acc.union(loc))
|
||||||
.unwrap_or(location)
|
.unwrap_or(location)
|
||||||
.map_end(|current| current - 1),
|
.map_end(|current| current - 1),
|
||||||
|
@ -2182,7 +2191,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
sample: UntypedExpr::Assignment {
|
sample: UntypedExpr::Assignment {
|
||||||
location: Span::empty(),
|
location: Span::empty(),
|
||||||
value: Box::new(subject.clone()),
|
value: Box::new(subject.clone()),
|
||||||
patterns: Vec1::new((clauses[0].patterns[0].clone(), None)),
|
patterns: AssignmentPattern::new(clauses[0].patterns[0].clone(), None).into(),
|
||||||
kind: AssignmentKind::let_(),
|
kind: AssignmentKind::let_(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue