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 unifier generated warning spans. #4421

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions sway-core/src/type_system/unify/unifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sway_error::{
type_error::TypeError,
warning::{CompileWarning, Warning},
};
use sway_types::{integer_bits::IntegerBits, Ident, Span, Spanned};
use sway_types::{integer_bits::IntegerBits, Ident, Span};

use crate::{engine_threading::*, language::ty, type_system::priv_prelude::*};

Expand Down Expand Up @@ -348,17 +348,13 @@ impl<'a> Unifier<'a> {
if rn == en && rfs.len() == efs.len() && rtps.len() == etps.len() {
rfs.iter().zip(efs.iter()).for_each(|(rf, ef)| {
append!(
self.unify(rf.type_argument.type_id, ef.type_argument.type_id, &rf.span),
self.unify(rf.type_argument.type_id, ef.type_argument.type_id, span),
warnings,
errors
);
});
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
append!(
self.unify(rtp.type_id, etp.type_id, &rtp.name_ident.span()),
warnings,
errors
);
append!(self.unify(rtp.type_id, etp.type_id, span), warnings, errors);
});
} else {
let (received, expected) = self.assign_args(received, expected);
Expand Down Expand Up @@ -387,17 +383,13 @@ impl<'a> Unifier<'a> {
if rn == en && rvs.len() == evs.len() && rtps.len() == etps.len() {
rvs.iter().zip(evs.iter()).for_each(|(rv, ev)| {
append!(
self.unify(rv.type_argument.type_id, ev.type_argument.type_id, &rv.span),
self.unify(rv.type_argument.type_id, ev.type_argument.type_id, span),
warnings,
errors
);
});
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
append!(
self.unify(rtp.type_id, etp.type_id, &rtp.name_ident.span()),
warnings,
errors
);
append!(self.unify(rtp.type_id, etp.type_id, span), warnings, errors);
});
} else {
let (received, expected) = self.assign_args(received, expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = 'core'
source = 'path+from-root-4FF9192341EE8DE7'

[[package]]
name = 'implicit_casting'
source = 'member'
dependencies = ['std']

[[package]]
name = 'std'
source = 'path+from-root-4FF9192341EE8DE7'
dependencies = ['core']
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "implicit_casting"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configurables": [],
"functions": [
{
"attributes": null,
"inputs": [],
"name": "main",
"output": {
"name": "",
"type": 0,
"typeArguments": null
}
}
],
"loggedTypes": [],
"messagesTypes": [],
"types": [
{
"components": null,
"type": "u64",
"typeId": 0,
"typeParameters": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
script;

use std::result::*;

struct MyStruct<T> {
#[allow(dead_code)]
a: T
}

fn main() -> u64 {
let _a: Result<u32, u8> = Result::Ok(5);

let _b: MyStruct<u32> = MyStruct{ a:5 };

42
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
category = "run"
expected_result = { action = "return", value = 42 }
validate_abi = true

# check: let _a: Result<u32, u8> = Result::Ok(5);
# nextln: $()This cast, from integer type of width sixty four to integer type of width thirty two, will lose precision.

# check: let _b: MyStruct<u32> = MyStruct{ a:5 };
# nextln: $()This cast, from integer type of width sixty four to integer type of width thirty two, will lose precision.

expected_warnings = 2