Skip to content

Commit

Permalink
Fixes build.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Aug 26, 2024
1 parent e736f2c commit 99d1f5b
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 105 deletions.
6 changes: 1 addition & 5 deletions sway-core/src/language/ty/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ impl HashWithEngines for TyCodeBlock {

impl SubstTypes for TyCodeBlock {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, ctx: &SubstTypesContext) -> HasChanges {
if ctx.subst_codeblocks {
self.contents.subst(type_mapping, ctx)
} else {
HasChanges::No
}
self.contents.subst(type_mapping, ctx)
}
}

Expand Down
21 changes: 15 additions & 6 deletions sway-core/src/language/ty/declaration/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,21 @@ impl HashWithEngines for TyFunctionDecl {

impl SubstTypes for TyFunctionDecl {
fn subst_inner(&mut self, type_mapping: &TypeSubstMap, ctx: &SubstTypesContext) -> HasChanges {
has_changes! {
self.type_parameters.subst(type_mapping, ctx);
self.parameters.subst(type_mapping, ctx);
self.return_type.subst(type_mapping, ctx);
self.body.subst(type_mapping, ctx);
self.implementing_for_typeid.subst(type_mapping, ctx);
if ctx.subst_function_body {
has_changes! {
self.type_parameters.subst(type_mapping, ctx);
self.parameters.subst(type_mapping, ctx);
self.return_type.subst(type_mapping, ctx);
self.body.subst(type_mapping, ctx);
self.implementing_for_typeid.subst(type_mapping, ctx);
}
} else {
has_changes! {
self.type_parameters.subst(type_mapping, ctx);
self.parameters.subst(type_mapping, ctx);
self.return_type.subst(type_mapping, ctx);
self.implementing_for_typeid.subst(type_mapping, ctx);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ pub(crate) fn instantiate_function_application(
{
cached_fn_ref
} else {
// Handle the trait constraints. This includes checking to see if the trait
// constraints are satisfied and replacing old decl ids based on the
// constraint with new decl ids based on the new type.
let decl_mapping = TypeParameter::gather_decl_mapping_from_trait_constraints(
handler,
ctx.by_ref(),
&function_decl.type_parameters,
function_decl.name.as_str(),
&call_path_binding.span(),
)?;

function_decl.replace_decls(&decl_mapping, handler, &mut ctx)?;
if !ctx.collecting_unifications() {
// Handle the trait constraints. This includes checking to see if the trait
// constraints are satisfied and replacing old decl ids based on the
// constraint with new decl ids based on the new type.
let decl_mapping = TypeParameter::gather_decl_mapping_from_trait_constraints(
handler,
ctx.by_ref(),
&function_decl.type_parameters,
function_decl.name.as_str(),
&call_path_binding.span(),
)?;

function_decl.replace_decls(&decl_mapping, handler, &mut ctx)?;
}

let method_sig = TyFunctionSig::from_fn_decl(&function_decl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,20 +679,22 @@ pub(crate) fn type_check_method_application(
}
}

// Handle the trait constraints. This includes checking to see if the trait
// constraints are satisfied and replacing old decl ids based on the
// constraint with new decl ids based on the new type.
let decl_mapping = TypeParameter::gather_decl_mapping_from_trait_constraints(
handler,
ctx.by_ref(),
&method.type_parameters,
method.name.as_str(),
&call_path.span(),
)
.ok();
if !ctx.collecting_unifications() {
// Handle the trait constraints. This includes checking to see if the trait
// constraints are satisfied and replacing old decl ids based on the
// constraint with new decl ids based on the new type.
let decl_mapping = TypeParameter::gather_decl_mapping_from_trait_constraints(
handler,
ctx.by_ref(),
&method.type_parameters,
method.name.as_str(),
&call_path.span(),
)
.ok();

if let Some(decl_mapping) = decl_mapping {
method.replace_decls(&decl_mapping, handler, &mut ctx)?;
if let Some(decl_mapping) = decl_mapping {
method.replace_decls(&decl_mapping, handler, &mut ctx)?;
}
}

let method_sig = TyFunctionSig::from_fn_decl(&method);
Expand Down
5 changes: 1 addition & 4 deletions sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,10 +1611,7 @@ impl<'a> TypeCheckContext<'a> {
call_site_span,
mod_path,
)?;
value.subst(
&type_mapping,
&SubstTypesContext::new(self.engines, !self.collecting_unifications()),
);
value.subst(&type_mapping, &SubstTypesContext::new(self.engines, true));
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/type_system/substitute/subst_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl std::ops::BitOr for HasChanges {

pub struct SubstTypesContext<'a> {
pub engines: &'a Engines,
pub subst_codeblocks: bool,
pub subst_function_body: bool,
}

impl<'a> SubstTypesContext<'a> {
pub fn new(engines: &Engines, subst_codeblocks: bool) -> SubstTypesContext {
pub fn new(engines: &Engines, subst_function_body: bool) -> SubstTypesContext {
SubstTypesContext {
engines,
subst_codeblocks,
subst_function_body,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: test/tests/tests.rs
assertion_line: 50
---
exit status: 1
stdout:
Expand All @@ -9,68 +10,6 @@ stdout:
Compiling script type_check_analyze_errors (test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors)

stderr:
error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:23:27
|
21 |
22 | let a = [None, Some(1), Some(1u8)];
23 | let _b: Option<u16> = a[1];
| ^^^^ Mismatched types.
expected: Option<u16>
found: Option<u8>.
help: Variable declaration's type annotation does not match up with the assigned expression's type.
24 |
25 | // Wrong cast
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:27:18
|
25 |
26 | let a = [8, 256u16, 8u8];
27 | let b: u32 = a[2];
| ^^^^ Mismatched types.
expected: u32
found: u16.
help: Variable declaration's type annotation does not match up with the assigned expression's type.
28 | }
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:4:14
|
2 |
3 | fn main() {
4 | let _a = 0x100;
| ^^^^^ Literal would overflow because its value does not fit into "u8"
5 | Vec::<u8>::new().push(_a);
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:8:14
|
6 |
7 | // u16
8 | let _a = 0x10000;
| ^^^^^^^ Literal would overflow because its value does not fit into "u16"
9 | Vec::<u16>::new().push(_a);
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:12:14
|
10 |
11 | // u32
12 | let _a = 0x100000000;
| ^^^^^^^^^^^ Literal would overflow because its value does not fit into "u32"
13 | Vec::<u32>::new().push(_a);
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:16:14
|
Expand Down Expand Up @@ -146,6 +85,21 @@ found: u64.
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:23:27
|
21 |
22 | let a = [None, Some(1), Some(1u8)];
23 | let _b: Option<u16> = a[1];
| ^^^^ Mismatched types.
expected: Option<u16>
found: Option<u8>.
help: Variable declaration's type annotation does not match up with the assigned expression's type.
24 |
25 | // Wrong cast
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:26:25
|
Expand All @@ -161,6 +115,20 @@ found: u8.
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:27:18
|
25 |
26 | let a = [8, 256u16, 8u8];
27 | let b: u32 = a[2];
| ^^^^ Mismatched types.
expected: u32
found: u16.
help: Variable declaration's type annotation does not match up with the assigned expression's type.
28 | }
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:31:22
|
Expand All @@ -176,5 +144,38 @@ found: u64.
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:4:14
|
2 |
3 | fn main() {
4 | let _a = 0x100;
| ^^^^^ Literal would overflow because its value does not fit into "u8"
5 | Vec::<u8>::new().push(_a);
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:8:14
|
6 |
7 | // u16
8 | let _a = 0x10000;
| ^^^^^^^ Literal would overflow because its value does not fit into "u16"
9 | Vec::<u16>::new().push(_a);
|
____

error
--> test/src/e2e_vm_tests/test_programs/should_fail/type_check_analyze_errors/src/main.sw:12:14
|
10 |
11 | // u32
12 | let _a = 0x100000000;
| ^^^^^^^^^^^ Literal would overflow because its value does not fit into "u32"
13 | Vec::<u32>::new().push(_a);
|
____

Aborting due to 12 errors.
error: Failed to compile type_check_analyze_errors

0 comments on commit 99d1f5b

Please sign in to comment.