Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/6861
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Feb 9, 2025
2 parents 45f03d8 + c288563 commit f5188d6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,35 @@ pub(crate) fn type_check_method_application(
true
}
});
handler.append(arg_handler);
handler.append(arg_handler.clone());
}

args_opt_buf.push_back((arg_opt, needs_second_pass));
args_opt_buf.push_back((arg_opt, arg_handler, needs_second_pass));
}

// 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, _has_errors)| match arg {
.map(|(arg, _, _has_errors)| match arg {
Some(arg) => arg.return_type,
None => type_engine.new_unknown(),
})
.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() {
handler.append(arg_handler.clone());
}
return Err(e);
} else {
method_result.unwrap()
};

let mut fn_ref = monomorphize_method(
handler,
Expand All @@ -120,7 +130,7 @@ pub(crate) fn type_check_method_application(
// 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), false) = arg_opt {
if let (Some(arg), _, false) = arg_opt {
args_buf.push_back(arg);
} else {
// We type check the argument expression again this time throwing out the error.
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 <contact@fuel.sh>"]
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 "add({unknown}, unknown)" found for type "{unknown}".

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

0 comments on commit f5188d6

Please sign in to comment.