Use rust-style turbofish
This commit is contained in:
parent
2cbeb4b551
commit
37d54499da
@ -152,15 +152,15 @@ impl AbstractNode for FunctionCall {
|
|||||||
|
|
||||||
let function_context = Context::new(Some(context.clone()));
|
let function_context = Context::new(Some(context.clone()));
|
||||||
|
|
||||||
if let Some(type_parameters) = function.type_parameters() {
|
if let (Some(type_parameters), Some(type_arguments)) =
|
||||||
for identifier in type_parameters {
|
(function.type_parameters(), self.type_arguments)
|
||||||
function_context.set_type(
|
{
|
||||||
identifier.clone(),
|
for (identifier, constructor) in
|
||||||
Type::Generic {
|
type_parameters.into_iter().zip(type_arguments.into_iter())
|
||||||
identifier: identifier.clone(),
|
{
|
||||||
concrete_type: None,
|
let r#type = constructor.construct(context)?;
|
||||||
},
|
|
||||||
)?;
|
function_context.set_type(identifier.clone(), r#type)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,10 +299,7 @@ impl InterpreterError {
|
|||||||
self.source_id.clone(),
|
self.source_id.clone(),
|
||||||
position.1,
|
position.1,
|
||||||
)
|
)
|
||||||
.with_message("An error occured that forced the program to exit.")
|
.with_message("An error occured that forced the program to exit. There may be unexpected side-effects because the program could not finish.")
|
||||||
.with_help(
|
|
||||||
"There may be unexpected side-effects because the program could not finish.",
|
|
||||||
)
|
|
||||||
.with_note(note)
|
.with_note(note)
|
||||||
.with_label(
|
.with_label(
|
||||||
Label::new((self.source_id.clone(), position.0..position.1)).with_message("Error occured here.")
|
Label::new((self.source_id.clone(), position.0..position.1)).with_message("Error occured here.")
|
||||||
@ -359,11 +356,17 @@ impl InterpreterError {
|
|||||||
),
|
),
|
||||||
ValidationError::RwLockPoison(_) => todo!(),
|
ValidationError::RwLockPoison(_) => todo!(),
|
||||||
ValidationError::TypeCheck {
|
ValidationError::TypeCheck {
|
||||||
conflict,
|
conflict: TypeConflict { actual, expected },
|
||||||
actual_position,
|
actual_position,
|
||||||
expected_position,
|
expected_position,
|
||||||
} => {
|
} => {
|
||||||
let TypeConflict { actual, expected } = conflict;
|
if let Type::Generic {
|
||||||
|
concrete_type: None,
|
||||||
|
..
|
||||||
|
} = actual
|
||||||
|
{
|
||||||
|
builder = builder.with_help("Try specifying the type using turbofish.");
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(position) = expected_position {
|
if let Some(position) = expected_position {
|
||||||
builder.add_label(
|
builder.add_label(
|
||||||
|
@ -414,19 +414,17 @@ pub fn parser<'src>(
|
|||||||
expression
|
expression
|
||||||
});
|
});
|
||||||
|
|
||||||
let turbofish = type_constructor
|
let turbofish = just(Token::Symbol(Symbol::DoubleColon)).ignore_then(
|
||||||
.clone()
|
type_constructor
|
||||||
.separated_by(just(Token::Symbol(Symbol::Comma)))
|
.clone()
|
||||||
.at_least(1)
|
.separated_by(just(Token::Symbol(Symbol::Comma)))
|
||||||
.collect()
|
.at_least(1)
|
||||||
.delimited_by(
|
.collect()
|
||||||
just(Token::Symbol(Symbol::ParenOpen)),
|
.delimited_by(
|
||||||
just(Token::Symbol(Symbol::ParenClose)),
|
just(Token::Symbol(Symbol::Less)),
|
||||||
)
|
just(Token::Symbol(Symbol::Greater)),
|
||||||
.delimited_by(
|
),
|
||||||
just(Token::Symbol(Symbol::DoubleColon)),
|
);
|
||||||
just(Token::Symbol(Symbol::DoubleColon)),
|
|
||||||
);
|
|
||||||
|
|
||||||
let atom = choice((
|
let atom = choice((
|
||||||
built_in_function.clone(),
|
built_in_function.clone(),
|
||||||
|
@ -539,7 +539,7 @@ fn function_call() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn function_call_with_type_arguments() {
|
fn function_call_with_type_arguments() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse(&lex("foobar::(str)::('hi')").unwrap()).unwrap()[0],
|
parse(&lex("foobar::<str>('hi')").unwrap()).unwrap()[0],
|
||||||
Statement::Expression(Expression::FunctionCall(
|
Statement::Expression(Expression::FunctionCall(
|
||||||
FunctionCall::new(
|
FunctionCall::new(
|
||||||
Expression::Identifier(Identifier::new("foobar").with_position((0, 6))),
|
Expression::Identifier(Identifier::new("foobar").with_position((0, 6))),
|
||||||
@ -547,10 +547,10 @@ fn function_call_with_type_arguments() {
|
|||||||
RawTypeConstructor::String.with_position((9, 12))
|
RawTypeConstructor::String.with_position((9, 12))
|
||||||
)]),
|
)]),
|
||||||
Some(vec![Expression::Value(
|
Some(vec![Expression::Value(
|
||||||
ValueNode::String("hi".to_string()).with_position((16, 20))
|
ValueNode::String("hi".to_string()).with_position((14, 18))
|
||||||
)]),
|
)]),
|
||||||
)
|
)
|
||||||
.with_position((0, 21))
|
.with_position((0, 19))
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ fn function_call_with_type_argument() {
|
|||||||
"test",
|
"test",
|
||||||
"
|
"
|
||||||
foobar = fn |T| (x: T) -> T { x }
|
foobar = fn |T| (x: T) -> T { x }
|
||||||
foobar::(int)::(42)
|
foobar::<int>(42)
|
||||||
",
|
",
|
||||||
),
|
),
|
||||||
Ok(Some(Value::integer(42)))
|
Ok(Some(Value::integer(42)))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
json = {
|
json = {
|
||||||
parse = fn |T| (input: str) -> T {
|
parse = fn |T| (input: str) -> T {
|
||||||
__JSON_PARSE__::(T)::(input)
|
__JSON_PARSE__::<T>(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user