Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes argument errors not displayed. #5909

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,55 @@ pub(crate) fn type_check_method_application(
.with_help_text("")
.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
if index == 0 {
args_opt_buf.push_back(ty::TyExpression::type_check(handler, ctx, arg.clone()).ok());
args_opt_buf.push_back((
ty::TyExpression::type_check(handler, ctx, arg.clone()).ok(),
None,
));
} else {
// Ignore errors in method parameters
// On the second pass we will throw the errors if they persist.
let arg_handler = Handler::default();
let arg_opt = ty::TyExpression::type_check(&arg_handler, ctx, arg.clone()).ok();
if arg_handler.has_errors() {
args_opt_buf.push_back(None);
args_opt_buf.push_back((None, Some(arg_handler)));
} else {
args_opt_buf.push_back(arg_opt);
args_opt_buf.push_back((arg_opt, None));
}
};
}

// resolve the method name to a typed function declaration and type_check
let (original_decl_ref, call_path_typeid) = resolve_method_name(
let method_result = resolve_method_name(
handler,
ctx.by_ref(),
&method_name_binding,
args_opt_buf
.iter()
.map(|arg| match arg {
Some(arg) => arg.return_type,
None => type_engine.insert(engines, TypeInfo::Unknown, None),
(Some(arg), _) => arg.return_type,
(None, _) => type_engine.insert(engines, TypeInfo::Unknown, None),
})
.collect(),
)?;
);

// In case resolve_method_name fails throw argument errors.
let (original_decl_ref, call_path_typeid) = if let Err(e) = method_result {
for (_, arg_handler) in args_opt_buf.iter() {
if let Some(arg_handler) = arg_handler.clone() {
handler.append(arg_handler);
}
}
return Err(e);
} else {
method_result.unwrap()
};

let method = decl_engine.get_function(&original_decl_ref);

// type check the function arguments (2nd pass)
let mut args_buf = VecDeque::new();
for (arg, index, arg_opt) in izip!(arguments.iter(), 0.., args_opt_buf.iter().cloned()) {
if let Some(arg) = arg_opt {
if let (Some(arg), _) = arg_opt {
args_buf.push_back(arg);
} else {
let param_index = if method.is_contract_call {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "core"
source = "path+from-root-1C5801B8398D8ED4"

[[package]]
name = "variable_does_not_exist"
source = "member"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "variable_does_not_exist"
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
script;

struct S {}

impl S {
fn associated(a: u64, b: u64, c: u64) -> u64 {
a + b + c
}
}

fn function(a: u64, b: u64, c: u64) -> u64 {
a + b + c
}

fn main() {
let _ = S::associated(x, y, z);


let _ = function(x, y, z);


let _ = x + y + z;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
category = "fail"

# check: $()let _ = S::associated(x, y, z);
# nextln:$()Variable "x" does not exist in this scope.

# check: $()let _ = S::associated(x, y, z);
# nextln:$()Variable "y" does not exist in this scope.

# check: $()let _ = S::associated(x, y, z);
# nextln:$()Variable "z" does not exist in this scope.

# check: $()let _ = function(x, y, z);
# nextln:$()Variable "x" does not exist in this scope.

# check: $()let _ = function(x, y, z);
# nextln:$()Variable "y" does not exist in this scope.

# check: $()let _ = function(x, y, z);
# nextln:$()Variable "z" does not exist in this scope.

# check: $()let _ = x + y + z;
# nextln: $()Variable "x" does not exist in this scope.

# check: $()let _ = x + y + z;
# nextln: $()Variable "y" does not exist in this scope.

# check: $()let _ = x + y + z;
# nextln: $()No method named "add" found for type "{unknown}".

# check: $()let _ = x + y + z;
# nextln: $()Variable "z" does not exist in this scope.