Bump 'is_validator_param' up from 'ArgName' to '...Arg'

There's no reasons for this to be a property of only ArgName::Named to begin with. And now, with the extra indirection introduced for arg_name, it may leads to subtle issues when patterns args are used in validators.
This commit is contained in:
KtorZ 2024-06-07 11:32:05 +02:00
parent 4d42c6cb19
commit b6da42baf2
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
17 changed files with 69 additions and 76 deletions

View File

@ -803,6 +803,7 @@ pub struct UntypedArg {
pub location: Span,
pub annotation: Option<Annotation>,
pub doc: Option<String>,
pub is_validator_param: bool,
}
impl UntypedArg {
@ -818,8 +819,6 @@ impl UntypedArg {
label: name.clone(),
name,
location: self.location,
// TODO: This should likely be moved up inside 'UntypedArg'.
is_validator_param: false,
}
}
}
@ -831,6 +830,7 @@ impl UntypedArg {
arg_name: self.arg_name(ix),
location: self.location,
annotation: self.annotation,
is_validator_param: self.is_validator_param,
doc: self.doc,
}
}
@ -842,6 +842,7 @@ pub struct TypedArg {
pub location: Span,
pub annotation: Option<Annotation>,
pub doc: Option<String>,
pub is_validator_param: bool,
pub tipo: Rc<Type>,
}
@ -928,7 +929,6 @@ pub enum ArgName {
name: String,
label: String,
location: Span,
is_validator_param: bool,
},
}

View File

@ -937,8 +937,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "self".to_string(),
label: "self".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
doc: None,
location: Span::empty(),
annotation: None,
@ -994,8 +994,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "a".to_string(),
label: "a".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,
@ -1050,8 +1050,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "a".to_string(),
label: "a".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,
@ -1063,6 +1063,7 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
label: "_b".to_string(),
location: Span::empty(),
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,
@ -1127,8 +1128,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "f".to_string(),
label: "f".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,
@ -1144,8 +1145,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "b".to_string(),
label: "b".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,
@ -1156,8 +1157,8 @@ pub fn prelude_functions(id_gen: &IdGenerator) -> IndexMap<FunctionAccessKey, Ty
name: "a".to_string(),
label: "a".to_string(),
location: Span::empty(),
is_validator_param: false,
},
is_validator_param: false,
location: Span::empty(),
annotation: None,
doc: None,

View File

@ -1201,8 +1201,8 @@ impl UntypedExpr {
label: name.clone(),
name,
location: Span::empty(),
is_validator_param: false,
}),
is_validator_param: false,
});
ast::CallArg {
@ -1362,6 +1362,7 @@ impl UntypedExpr {
location,
doc: None,
annotation,
is_validator_param: false,
by: ArgBy::ByName(arg_name),
})
.collect(),

View File

@ -65,24 +65,23 @@ pub fn param(is_validator_param: bool) -> impl Parser<Token, ast::UntypedArg, Er
}),
select! {Token::Name {name} => name}
.then(select! {Token::Name {name} => name})
.map_with_span(move |(label, name), span| ast::ArgName::Named {
.map_with_span(|(label, name), span| ast::ArgName::Named {
label,
name,
location: span,
is_validator_param,
}),
select! {Token::Name {name} => name}.map_with_span(move |name, span| ast::ArgName::Named {
select! {Token::Name {name} => name}.map_with_span(|name, span| ast::ArgName::Named {
label: name.clone(),
name,
location: span,
is_validator_param,
}),
))
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.map_with_span(|(arg_name, annotation), span| ast::UntypedArg {
.map_with_span(move |(arg_name, annotation), span| ast::UntypedArg {
location: span,
annotation,
doc: None,
is_validator_param,
by: ByName(arg_name),
})
}

View File

@ -12,12 +12,12 @@ Test(
name: "x",
label: "x",
location: 9..10,
is_validator_param: false,
},
),
location: 9..10,
annotation: None,
doc: None,
is_validator_param: false,
},
via: Var {
location: 15..16,
@ -31,12 +31,12 @@ Test(
name: "y",
label: "y",
location: 18..19,
is_validator_param: false,
},
),
location: 18..19,
annotation: None,
doc: None,
is_validator_param: false,
},
via: Var {
location: 24..25,

View File

@ -12,12 +12,12 @@ Test(
name: "x",
label: "x",
location: 9..10,
is_validator_param: false,
},
),
location: 9..10,
annotation: None,
doc: None,
is_validator_param: false,
},
via: FieldAccess {
location: 15..27,

View File

@ -12,7 +12,6 @@ Test(
name: "x",
label: "x",
location: 9..10,
is_validator_param: false,
},
),
location: 9..15,
@ -25,6 +24,7 @@ Test(
},
),
doc: None,
is_validator_param: false,
},
via: Call {
arguments: [],

View File

@ -14,12 +14,12 @@ Validator(
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
),
location: 21..26,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -27,12 +27,12 @@ Validator(
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
),
location: 28..32,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -40,12 +40,12 @@ Validator(
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
),
location: 34..37,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: Var {
@ -70,12 +70,12 @@ Validator(
name: "rdmr",
label: "rdmr",
location: 64..68,
is_validator_param: false,
},
),
location: 64..68,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -83,12 +83,12 @@ Validator(
name: "ctx",
label: "ctx",
location: 70..73,
is_validator_param: false,
},
),
location: 70..73,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: Var {

View File

@ -14,12 +14,12 @@ Validator(
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
),
location: 21..26,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -27,12 +27,12 @@ Validator(
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
),
location: 28..32,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -40,12 +40,12 @@ Validator(
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
),
location: 34..37,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: Var {

View File

@ -60,13 +60,10 @@ pub fn via() -> impl Parser<Token, ast::UntypedArgVia, Error = ParseError> {
location: span,
}
}),
select! {Token::Name {name} => name}.map_with_span(move |name, location| {
ast::ArgName::Named {
label: name.clone(),
name,
location,
is_validator_param: false,
}
select! {Token::Name {name} => name}.map_with_span(|name, location| ast::ArgName::Named {
label: name.clone(),
name,
location,
}),
))
.then(just(Token::Colon).ignore_then(annotation()).or_not())
@ -79,6 +76,7 @@ pub fn via() -> impl Parser<Token, ast::UntypedArgVia, Error = ParseError> {
annotation,
location,
doc: None,
is_validator_param: false,
},
via,
})

View File

@ -45,8 +45,8 @@ pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
name: "left".to_string(),
label: "left".to_string(),
location,
is_validator_param: false,
}),
is_validator_param: false,
annotation: arg_annotation.clone(),
doc: None,
location,
@ -56,8 +56,8 @@ pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
name: "right".to_string(),
label: "right".to_string(),
location,
is_validator_param: false,
}),
is_validator_param: false,
annotation: arg_annotation,
doc: None,
location,

View File

@ -42,11 +42,11 @@ pub fn params() -> impl Parser<Token, ast::UntypedArg, Error = ParseError> {
label: name.clone(),
name,
location: span,
is_validator_param: false,
}),
))
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.map_with_span(|(arg_name, annotation), span| ast::UntypedArg {
is_validator_param: false,
location: span,
annotation,
doc: None,

View File

@ -12,7 +12,6 @@ Fn {
name: "a",
label: "a",
location: 4..5,
is_validator_param: false,
},
),
location: 4..10,
@ -25,6 +24,7 @@ Fn {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {

View File

@ -30,7 +30,6 @@ Sequence {
name: "left",
label: "left",
location: 16..17,
is_validator_param: false,
},
),
location: 16..17,
@ -43,6 +42,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -50,7 +50,6 @@ Sequence {
name: "right",
label: "right",
location: 16..17,
is_validator_param: false,
},
),
location: 16..17,
@ -63,6 +62,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -127,7 +127,6 @@ Sequence {
name: "left",
label: "left",
location: 38..40,
is_validator_param: false,
},
),
location: 38..40,
@ -140,6 +139,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -147,7 +147,6 @@ Sequence {
name: "right",
label: "right",
location: 38..40,
is_validator_param: false,
},
),
location: 38..40,
@ -160,6 +159,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -224,7 +224,6 @@ Sequence {
name: "left",
label: "left",
location: 61..62,
is_validator_param: false,
},
),
location: 61..62,
@ -237,6 +236,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -244,7 +244,6 @@ Sequence {
name: "right",
label: "right",
location: 61..62,
is_validator_param: false,
},
),
location: 61..62,
@ -257,6 +256,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -321,7 +321,6 @@ Sequence {
name: "left",
label: "left",
location: 83..85,
is_validator_param: false,
},
),
location: 83..85,
@ -334,6 +333,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -341,7 +341,6 @@ Sequence {
name: "right",
label: "right",
location: 83..85,
is_validator_param: false,
},
),
location: 83..85,
@ -354,6 +353,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -418,12 +418,12 @@ Sequence {
name: "left",
label: "left",
location: 106..108,
is_validator_param: false,
},
),
location: 106..108,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -431,12 +431,12 @@ Sequence {
name: "right",
label: "right",
location: 106..108,
is_validator_param: false,
},
),
location: 106..108,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -501,12 +501,12 @@ Sequence {
name: "left",
label: "left",
location: 129..131,
is_validator_param: false,
},
),
location: 129..131,
annotation: None,
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -514,12 +514,12 @@ Sequence {
name: "right",
label: "right",
location: 129..131,
is_validator_param: false,
},
),
location: 129..131,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -584,7 +584,6 @@ Sequence {
name: "left",
label: "left",
location: 152..154,
is_validator_param: false,
},
),
location: 152..154,
@ -597,6 +596,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -604,7 +604,6 @@ Sequence {
name: "right",
label: "right",
location: 152..154,
is_validator_param: false,
},
),
location: 152..154,
@ -617,6 +616,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -681,7 +681,6 @@ Sequence {
name: "left",
label: "left",
location: 175..177,
is_validator_param: false,
},
),
location: 175..177,
@ -694,6 +693,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -701,7 +701,6 @@ Sequence {
name: "right",
label: "right",
location: 175..177,
is_validator_param: false,
},
),
location: 175..177,
@ -714,6 +713,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -778,7 +778,6 @@ Sequence {
name: "left",
label: "left",
location: 198..199,
is_validator_param: false,
},
),
location: 198..199,
@ -791,6 +790,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -798,7 +798,6 @@ Sequence {
name: "right",
label: "right",
location: 198..199,
is_validator_param: false,
},
),
location: 198..199,
@ -811,6 +810,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -875,7 +875,6 @@ Sequence {
name: "left",
label: "left",
location: 220..221,
is_validator_param: false,
},
),
location: 220..221,
@ -888,6 +887,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -895,7 +895,6 @@ Sequence {
name: "right",
label: "right",
location: 220..221,
is_validator_param: false,
},
),
location: 220..221,
@ -908,6 +907,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -972,7 +972,6 @@ Sequence {
name: "left",
label: "left",
location: 242..243,
is_validator_param: false,
},
),
location: 242..243,
@ -985,6 +984,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -992,7 +992,6 @@ Sequence {
name: "right",
label: "right",
location: 242..243,
is_validator_param: false,
},
),
location: 242..243,
@ -1005,6 +1004,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -1069,7 +1069,6 @@ Sequence {
name: "left",
label: "left",
location: 264..265,
is_validator_param: false,
},
),
location: 264..265,
@ -1082,6 +1081,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -1089,7 +1089,6 @@ Sequence {
name: "right",
label: "right",
location: 264..265,
is_validator_param: false,
},
),
location: 264..265,
@ -1102,6 +1101,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {
@ -1166,7 +1166,6 @@ Sequence {
name: "left",
label: "left",
location: 286..287,
is_validator_param: false,
},
),
location: 286..287,
@ -1179,6 +1178,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
UntypedArg {
by: ByName(
@ -1186,7 +1186,6 @@ Sequence {
name: "right",
label: "right",
location: 286..287,
is_validator_param: false,
},
),
location: 286..287,
@ -1199,6 +1198,7 @@ Sequence {
},
),
doc: None,
is_validator_param: false,
},
],
body: BinOp {

View File

@ -53,12 +53,12 @@ Sequence {
name: "_capture__0",
label: "_capture__0",
location: 0..0,
is_validator_param: false,
},
),
location: 0..0,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: Call {
@ -84,12 +84,12 @@ Sequence {
name: "y",
label: "y",
location: 52..53,
is_validator_param: false,
},
),
location: 52..53,
annotation: None,
doc: None,
is_validator_param: false,
},
],
body: BinOp {

View File

@ -1085,6 +1085,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
annotation,
location,
doc,
is_validator_param,
} = untyped_arg;
let tipo = annotation
@ -1106,6 +1107,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
location,
annotation,
tipo,
is_validator_param,
doc,
})
}
@ -1737,12 +1739,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
for arg in &args {
match &arg.arg_name {
ArgName::Named {
name,
is_validator_param,
location,
..
} if !is_validator_param => {
ArgName::Named { name, location, .. } if !arg.is_validator_param => {
if let Some(duplicate_location) = argument_names.insert(name, location) {
return Err(Error::DuplicateArgument {
location: *location,
@ -1969,7 +1966,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
label: name.clone(),
name,
location: var_location,
is_validator_param: false,
};
names.push((name, assignment_pattern_location, annotation));
@ -1993,7 +1989,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
label: name.clone(),
name: name.clone(),
location: pattern.location(),
is_validator_param: false,
};
let pattern_is_var = pattern.is_var();

View File

@ -206,10 +206,9 @@ fn infer_definition(
match &arg.arg_name(ix) {
ArgName::Named {
name,
is_validator_param,
label: _,
location: _,
} if *is_validator_param => {
} if arg.is_validator_param => {
environment.insert_variable(
name.to_string(),
ValueConstructorVariant::LocalVariable {