diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-27 14:33:31 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-27 14:33:31 -0700 |
| commit | 0a265867242757accd9a8dafee2f6cce7c738f29 (patch) | |
| tree | cf0b31ca6c5e898f898a343a995db5d5aad57094 /src/analyze.cpp | |
| parent | 707154da36ee10c7893cacfafdd3034385d69103 (diff) | |
| download | zig-0a265867242757accd9a8dafee2f6cce7c738f29.tar.gz zig-0a265867242757accd9a8dafee2f6cce7c738f29.zip | |
fix comparing incompatible number literals crash
closes #94
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 992e0e7fbb..0ca480fdd0 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1234,14 +1234,19 @@ static bool num_lit_fits_in_other_type(CodeGen *g, AstNode *literal_node, TypeTa { return true; } - } else if (other_type->id == TypeTableEntryIdNumLitFloat || - other_type->id == TypeTableEntryIdNumLitInt) + } else if ((other_type->id == TypeTableEntryIdNumLitFloat && + const_val->data.x_bignum.kind == BigNumKindFloat) || + (other_type->id == TypeTableEntryIdNumLitInt && + const_val->data.x_bignum.kind == BigNumKindInt)) { return true; } + const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer"; + add_node_error(g, literal_node, - buf_sprintf("value %s cannot be represented in type '%s'", + buf_sprintf("%s value %s cannot be implicitly casted to type '%s'", + num_lit_str, buf_ptr(bignum_to_buf(&const_val->data.x_bignum)), buf_ptr(&other_type->name))); return false; @@ -1351,14 +1356,6 @@ static TypeTableEntry *determine_peer_type_compatibility(CodeGen *g, AstNode *pa prev_type = cur_type; prev_node = cur_node; continue; - } else if (prev_type->id == TypeTableEntryIdNumLitFloat && - cur_type->id == TypeTableEntryIdNumLitFloat) - { - continue; - } else if (prev_type->id == TypeTableEntryIdNumLitInt && - cur_type->id == TypeTableEntryIdNumLitInt) - { - continue; } else if (prev_type->id == TypeTableEntryIdNumLitInt || prev_type->id == TypeTableEntryIdNumLitFloat) { |
