Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 19, 2023
1 parent 6fc48bf commit 564bc01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/typecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@ static void do_explicit_cast(ExpressionTypes *types, const Type *to, Location lo
const Type *from = types->type;

if (from == to)
fail(location, "unnecessary cast from %s to %s", from->name, to->name);
show_warning(location, "unnecessary cast from %s to %s", from->name, to->name);

if (
!(from->kind == TYPE_ARRAY && to->kind == TYPE_POINTER && from->data.array.membertype == to->data.valuetype)
from != to
&& !(from->kind == TYPE_ARRAY && to->kind == TYPE_POINTER && from->data.array.membertype == to->data.valuetype)
&& !(is_pointer_type(from) && is_pointer_type(to))
&& !(is_number_type(from) && is_number_type(to))
&& !(is_integer_type(from) && to->kind == TYPE_ENUM)
Expand Down
3 changes: 0 additions & 3 deletions tests/other_errors/unnecessary_cast.jou

This file was deleted.

6 changes: 6 additions & 0 deletions tests/should_succeed/unnecessary_cast_warning.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "stdlib/io.jou"

def main() -> int:
x = 1 as int # Warning: unnecessary cast from int to int
printf("%d\n", x) # Output: 1
return 0

0 comments on commit 564bc01

Please sign in to comment.