Skip to content

Commit

Permalink
Merge branch 'master' into xunilrj/check-monomorphization-non-parent-…
Browse files Browse the repository at this point in the history
…only
  • Loading branch information
JoshuaBatty authored Sep 18, 2024
2 parents e53de8f + 520bfe9 commit 0705c89
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,7 @@ impl TypeCheckAnalysis for ty::ImplSelfOrTrait {
ctx.push_nodes_for_impl_trait(self);

// Now lets analyze each impl trait item.
for (i, item) in impl_trait.items.iter().enumerate() {
let _node = ctx.items_node_stack[i];
for item in impl_trait.items.iter() {
item.type_check_analyze(handler, ctx)?;
}

Expand Down
6 changes: 6 additions & 0 deletions sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,12 @@ impl Root {
ty::TyDecl::EnumDecl(enum_ty_decl) => TypeInfo::Enum(enum_ty_decl.decl_id),
ty::TyDecl::TraitTypeDecl(type_decl) => {
let type_decl = engines.de().get_type(&type_decl.decl_id);
if type_decl.ty.is_none() {
return Err(handler.emit_err(CompileError::Internal(
"Trait type declaration has no type",
symbol.span(),
)));
}
(*engines.te().get(type_decl.ty.clone().unwrap().type_id)).clone()
}
_ => {
Expand Down
9 changes: 7 additions & 2 deletions sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4943,8 +4943,13 @@ pub fn cfg_eval(
}
},
_ => {
// Already checked with `AttributeKind::expected_args_*`
unreachable!("cfg attribute should only have the `target` or the `program_type` argument");
return Err(handler.emit_err(
ConvertParseTreeError::InvalidCfgArg {
span: arg.span(),
value: arg.name.as_str().to_string(),
}
.into(),
));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions sway-error/src/convert_parse_tree_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub enum ConvertParseTreeError {
ExpectedCfgProgramTypeArgValue { span: Span },
#[error("Expected \"true\" or \"false\" for experimental_new_encoding")]
ExpectedExperimentalNewEncodingArgValue { span: Span },
#[error("Unexpected attribute value: \"{value}\" for attribute: \"cfg\"")]
InvalidCfgArg { span: Span, value: String },
}

impl Spanned for ConvertParseTreeError {
Expand Down Expand Up @@ -182,6 +184,7 @@ impl Spanned for ConvertParseTreeError {
ConvertParseTreeError::InvalidCfgProgramTypeArgValue { span, .. } => span.clone(),
ConvertParseTreeError::ExpectedCfgProgramTypeArgValue { span } => span.clone(),
ConvertParseTreeError::ExpectedExperimentalNewEncodingArgValue { span } => span.clone(),
ConvertParseTreeError::InvalidCfgArg { span, .. } => span.clone(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "core"
source = "path+from-root-3F7C73944D096B89"

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

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
script;
trait T2 {}
trait T1: T2 {
fn new() -> Self;
}

struct S {}
impl T2 for S {}
impl T1 for S {
fn new() -> Self {
S {}
}
}

fn bar<T>() -> T
where
T: T1,
{
T::new()
}

fn foo<T>() -> T
where
T: T2,
{
bar()
}

fn main() -> u64 {
let _:S = foo();
42
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()bar()
# nextln: $()Trait "T1" is not implemented for type "T".
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "invalid_cfg_arg"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "invalid_cfg_arg"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
predicate;
#[cfg(c)] a
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
category = "fail"

# check: $()#[cfg(c)] a
# nextln: $()Unexpected attribute value: "c" for attribute: "cfg" expected value "target" or "program_type" or "experimental_new_encoding"

# check: $()#[cfg(c)] a
# nextln: $()Expected an item.

# check: $()#[cfg(c)] a
# nextln: $()Unexpected attribute value: "c" for attribute: "cfg"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "core"
source = "path+from-root-F62FA9D54ABC8F01"

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

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

struct Struct{x:u}
impl Struct{
fn w()->f{{(()}}
trait Supertrait{}
impl Supertrait for Struct{)
}

fn s<A>(b:B) where A:t{}fn n(){}

fn main() -> u64 {
0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()fn w()->f{{(()}}
# nextln: $()mismatched delimiters
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "core"
source = "path+from-root-6C2FF70C66B98326"

[[package]]
name = "parser_associated_type_error"
source = "member"
dependencies = ["std"]

[[package]]
name = "std"
source = "path+from-root-6C2FF70C66B98326"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "parser_associated_type_error"

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

trait T{type E const C:Self::E::E}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
category = "fail"

# check: $()trait T{type E const C:Self::E::E}
# nextln: $()Expected `;`.

# check: $()Trait type declaration has no type

0 comments on commit 0705c89

Please sign in to comment.