Skip to content

Commit

Permalink
Fixes generic enums and structs type ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jul 15, 2024
1 parent 8308dea commit 3ebe4fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
22 changes: 18 additions & 4 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use sway_types::integer_bits::IntegerBits;

use crate::{language::CallPath, Engines, TypeArgument, TypeId, TypeInfo};

#[derive(Clone)]
pub struct AbiStrContext {
pub program_name: Option<String>,
pub abi_with_callpaths: bool,
pub abi_with_fully_specified_types: bool,
pub abi_with_generic_type_parameters: bool,
}

impl TypeId {
Expand Down Expand Up @@ -39,7 +41,13 @@ impl TypeId {
.iter()
.map(|f| {
if ctx.abi_with_fully_specified_types {
type_engine.get(f.type_id).abi_str(ctx, engines)
type_engine.get(f.type_id).abi_str(
&AbiStrContext {
abi_with_generic_type_parameters: true,
..ctx.clone()
},
engines,
)
} else {
"_".to_string()
}
Expand All @@ -50,7 +58,13 @@ impl TypeId {
(TypeInfo::Array(_, count), TypeInfo::Array(type_arg, resolved_count)) => {
assert_eq!(count.val(), resolved_count.val());
let inner_type = if ctx.abi_with_fully_specified_types {
type_engine.get(type_arg.type_id).abi_str(ctx, engines)
type_engine.get(type_arg.type_id).abi_str(
&AbiStrContext {
abi_with_generic_type_parameters: true,
..ctx.clone()
},
engines,
)
} else {
"_".to_string()
};
Expand Down Expand Up @@ -105,7 +119,7 @@ impl TypeInfo {
Enum(decl_ref) => {
let decl = decl_engine.get_enum(decl_ref);
let type_params =
if !ctx.abi_with_fully_specified_types || decl.type_parameters.is_empty() {
if !ctx.abi_with_generic_type_parameters || decl.type_parameters.is_empty() {
"".into()
} else {
format!(
Expand All @@ -126,7 +140,7 @@ impl TypeInfo {
Struct(decl_ref) => {
let decl = decl_engine.get_struct(decl_ref);
let type_params =
if !ctx.abi_with_fully_specified_types || decl.type_parameters.is_empty() {
if !ctx.abi_with_generic_type_parameters || decl.type_parameters.is_empty() {
"".into()
} else {
format!(
Expand Down
10 changes: 4 additions & 6 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ pub struct AbiContext<'a> {
}

impl<'a> AbiContext<'a> {
fn to_str_context(
&self,
engines: &Engines,
abi_with_fully_specified_types: bool,
) -> AbiStrContext {
fn to_str_context(&self, engines: &Engines, abi_full: bool) -> AbiStrContext {
AbiStrContext {
program_name: self
.program
Expand All @@ -32,7 +28,8 @@ impl<'a> AbiContext<'a> {
.program_id(engines)
.read(engines, |m| m.name.clone().map(|v| v.as_str().to_string())),
abi_with_callpaths: self.abi_with_callpaths,
abi_with_fully_specified_types,
abi_with_fully_specified_types: abi_full,
abi_with_generic_type_parameters: abi_full,
}
}
}
Expand All @@ -55,6 +52,7 @@ impl TypeId {
.read(engines, |m| m.name.clone().map(|v| v.as_str().to_string())),
abi_with_callpaths: true,
abi_with_fully_specified_types: true,
abi_with_generic_type_parameters: false,
},
engines,
resolved_type_id,
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/language/ty/expression/intrinsic_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl CollectTypesMetadata for TyIntrinsicFunctionKind {
program_name: Some(ctx.program_name.clone()),
abi_with_callpaths: true,
abi_with_fully_specified_types: true,
abi_with_generic_type_parameters: true,
},
ctx.engines,
logged_type,
Expand Down

0 comments on commit 3ebe4fd

Please sign in to comment.