| author | |
| committer | |
| log | 64034a3d1aeede8e0a5c8bd44d672a1d7902d981 |
| tree | 3c7ea61fd5cf169d307a958cf3a5fe0fcf6e31d2 |
| parent | cfaced3f73da2d5fc82f063715d51e06084baee8 |
closes #1703 files changed, 18 insertions(+), 4 deletions(-)
src/analyze.cpp+7-4| ... | ... | @@ -4326,10 +4326,13 @@ static TypeTableEntry *analyze_min_max_value(CodeGen *g, ImportTableEntry *impor |
| 4326 | 4326 | |
| 4327 | 4327 | if (type_entry->id == TypeTableEntryIdInvalid) { |
| 4328 | 4328 | return g->builtin_types.entry_invalid; |
| 4329 | } else if (type_entry->id == TypeTableEntryIdInt || | |
| 4330 | type_entry->id == TypeTableEntryIdFloat || | |
| 4331 | type_entry->id == TypeTableEntryIdBool) | |
| 4332 | { | |
| 4329 | } else if (type_entry->id == TypeTableEntryIdInt) { | |
| 4330 | eval_min_max_value(g, type_entry, &get_resolved_expr(node)->const_val, is_max); | |
| 4331 | return g->builtin_types.entry_num_lit_int; | |
| 4332 | } else if (type_entry->id == TypeTableEntryIdFloat) { | |
| 4333 | eval_min_max_value(g, type_entry, &get_resolved_expr(node)->const_val, is_max); | |
| 4334 | return g->builtin_types.entry_num_lit_float; | |
| 4335 | } else if (type_entry->id == TypeTableEntryIdBool) { | |
| 4333 | 4336 | eval_min_max_value(g, type_entry, &get_resolved_expr(node)->const_val, is_max); |
| 4334 | 4337 | return type_entry; |
| 4335 | 4338 | } else { |
test/cases/max_value_type.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 3 | #attribute("test") | |
| 4 | fn maxValueType() { | |
| 5 | // If the type of @maxValue(i32) was i32 then this implicit cast to | |
| 6 | // u32 would not work. But since the value is a number literal, | |
| 7 | // it works fine. | |
| 8 | const x: u32 = @maxValue(i32); | |
| 9 | assert(x == 2147483647); | |
| 10 | } |
test/self_hosted.zig+1| ... | ... | @@ -7,6 +7,7 @@ const test_return_type_type = @import("cases/return_type_type.zig"); |
| 7 | 7 | const test_zeroes = @import("cases/zeroes.zig"); |
| 8 | 8 | const test_sizeof_and_typeof = @import("cases/sizeof_and_typeof.zig"); |
| 9 | 9 | const test_maybe_return = @import("cases/maybe_return.zig"); |
| 10 | const test_max_value_type = @import("cases/max_value_type.zig"); | |
| 10 | 11 | |
| 11 | 12 | // normal comment |
| 12 | 13 | /// this is a documentation comment |