Skip to content

Commit 2dde5fb

Browse files
committed
PR fixes
1 parent a6a9aa0 commit 2dde5fb

5 files changed

Lines changed: 14 additions & 29 deletions

File tree

sway-core/src/language/ty/expression/expression_variant.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,13 +1330,6 @@ impl TypeCheckFinalization for TyExpressionVariant {
13301330
for expr in kind.arguments.iter_mut() {
13311331
expr.type_check_finalize(handler, ctx)?;
13321332
}
1333-
1334-
if let sway_ast::Intrinsic::EnumVariantsValues = kind.kind {
1335-
eprintln!(
1336-
"type_check_finalize: {:?}",
1337-
ctx.engines.help_out(&kind.type_arguments)
1338-
);
1339-
}
13401333
}
13411334
TyExpressionVariant::AbiName(_) => {
13421335
todo!("")

sway-core/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,10 +1198,6 @@ pub fn compile_to_asm(
11981198
experimental,
11991199
)?;
12001200

1201-
if let Ok(t) = ast_res.typed.as_ref() {
1202-
dbg!(&t.decls_to_check);
1203-
}
1204-
12051201
ast_to_asm(handler, engines, &ast_res, build_config, experimental)
12061202
}
12071203

sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn type_check_enum_variants_values(
187187
if arguments.len() != 1 {
188188
return Err(handler.emit_err(CompileError::IntrinsicIncorrectNumArgs {
189189
name: kind.to_string(),
190-
expected: 0,
190+
expected: 1,
191191
span,
192192
}));
193193
}
@@ -200,7 +200,7 @@ fn type_check_enum_variants_values(
200200

201201
let _value_id = match first_argument_typed_expr.expression {
202202
ty::TyExpressionVariant::Literal(Literal::U64(3)) => 3,
203-
_ => todo!(),
203+
_ => return Err(handler.emit_err(CompileError::InvalidArgument { span: first_argument_typed_expr.span })),
204204
};
205205

206206
let arguments = vec![first_argument_typed_expr];
@@ -232,16 +232,6 @@ fn type_check_enum_variants_values(
232232
};
233233
let return_type = ctx.engines.te().insert_slice(ctx.engines, elem_type);
234234

235-
match &*ctx.engines.te().get(arg) {
236-
TypeInfo::UnknownGeneric { .. } => {}
237-
TypeInfo::Enum(_) => {
238-
todo!();
239-
}
240-
_ => {
241-
todo!()
242-
}
243-
};
244-
245235
let mut final_type_arguments = type_arguments.to_vec();
246236
*final_type_arguments[0].type_id_mut() = arg;
247237

sway-error/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ pub enum CompileError {
501501
},
502502
#[error("This opcode takes an immediate value but none was provided.")]
503503
MissingImmediate { span: Span },
504+
#[error("Invalid argument.")]
505+
InvalidArgument { span: Span },
504506
#[error("This immediate value is invalid.")]
505507
InvalidImmediateValue { span: Span },
506508
#[error("Variant \"{variant_name}\" does not exist on enum \"{enum_name}\"")]
@@ -1370,6 +1372,7 @@ impl Spanned for CompileError {
13701372
IndexedFieldOffsetTooLarge { field_name } => field_name.span(),
13711373
IncoherentImplDueToOrphanRule { span, .. } => span.clone(),
13721374
TrivialCheckFailed { span, .. } => span.clone(),
1375+
InvalidArgument { span } => span.clone(),
13731376
}
13741377
}
13751378
}

sway-lib-std/src/codec.sw

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6905,10 +6905,10 @@ fn trivial_bool_when_valid() {
69056905
assert_encoding(b, [0u8, 0, 0, 0, 0, 0, 0, 1]);
69066906
}
69076907

6908-
#[test(should_revert)]
6908+
#[test]
69096909
fn trivial_bool_when_invalid_is_valid() {
6910-
let slice = encode(TrivialBool { value: 2 });
6911-
let _ = abi_decode::<TrivialBool>(slice).unwrap();
6910+
let bytes = encode(TrivialBool { value: 2 });
6911+
assert_eq(abi_decode::<TrivialBool>(bytes).is_valid(), false, 0);
69126912
}
69136913

69146914
#[test(should_revert)]
@@ -6934,9 +6934,12 @@ where
69346934
let discriminant: u64 = abi_decode::<u64>(discriminant);
69356935

69366936
let is_decode_trivial_table = T::is_decode_trivial_table();
6937-
let a: bool = *__elem_at(is_decode_trivial_table, discriminant);
6938-
6939-
discriminant < is_decode_trivial_table.len() && a
6937+
6938+
if discriminant < is_decode_trivial_table.len() {
6939+
*__elem_at(is_decode_trivial_table, discriminant)
6940+
} else {
6941+
false
6942+
}
69406943
}
69416944

69426945
pub fn unwrap(self) -> T {

0 commit comments

Comments
 (0)