Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
g-r-a-n-t committed Dec 17, 2020
1 parent f286785 commit 0033117
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion compiler/tests/compile_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::fs;
case("return_lt_mixed_types.fe", "TypeError"),
case("indexed_event.fe", "MoreThanThreeIndexedParams"),
case("unary_minus_on_bool.fe", "TypeError"),
case("type_constructor_from_variable.fe", "NumericLiteralExpected")
case("type_constructor_from_variable.fe", "NumericLiteralExpected"),
case("needs_mem_copy.fe", "CannotMove")
)]
fn test_compile_errors(fixture_file: &str, expected_error: &str) {
Expand Down
31 changes: 21 additions & 10 deletions semantics/src/traversal/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ fn expr_unary_operation(
) -> Result<ExpressionAttributes, SemanticError> {
if let fe::Expr::UnaryOperation { op, operand } = &exp.node {
if let fe::UnaryOperator::USub = &op.node {
let operand_attributes =
expr_with_value_move(Rc::clone(&scope), Rc::clone(&context), operand)?;
let operand_attributes = value_expr(Rc::clone(&scope), Rc::clone(&context), operand)?;

if !matches!(operand_attributes.typ, Type::Base(Base::Numeric(_))) {
return Err(SemanticError::type_error());
Expand Down Expand Up @@ -336,10 +335,10 @@ fn expr_call_type_constructor(
typ: Type,
args: &Spanned<Vec<Spanned<fe::CallArg>>>,
) -> Result<ExpressionAttributes, SemanticError> {
// TODO: check that there is only one param
if argument_attributes.len() != 1 {
if args.node.len() != 1 {
return Err(SemanticError::type_error());
}

validate_is_numeric_literal(&args.node[0].node)?;
call_arg(scope, context, &args.node[0])?;
Ok(ExpressionAttributes::new(typ, Location::Value))
Expand Down Expand Up @@ -467,12 +466,24 @@ fn expr_name_call_type(
"u8" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::U8)),
}),
"i256" => Type::Base(Base::Numeric(Integer::I256)),
"i128" => Type::Base(Base::Numeric(Integer::I128)),
"i64" => Type::Base(Base::Numeric(Integer::I64)),
"i32" => Type::Base(Base::Numeric(Integer::I32)),
"i16" => Type::Base(Base::Numeric(Integer::I16)),
"i8" => Type::Base(Base::Numeric(Integer::I8)),
"i256" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I256)),
}),
"i128" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I128)),
}),
"i64" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I64)),
}),
"i32" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I32)),
}),
"i16" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I16)),
}),
"i8" => Ok(CallType::TypeConstructor {
typ: Type::Base(Base::Numeric(Integer::I8)),
}),
_ => Err(SemanticError::undefined_value()),
}
}
Expand Down

0 comments on commit 0033117

Please sign in to comment.