authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-01 01:33:23-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-07-01 01:33:23-04:00
log4c0e280d6da47ac16e32ef8c8bfa4629c4e4a57a
tree912285190ec6b6f19c871363f6d1fe097d8c1a5c
parent42033ea3ca126ff1f3e5555ba56cc5a7adeb3d6b
parentb182151de5a215b97de3ef3742ebdc5af7e66119
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1185 from ziglang/undefined-at-comptime-improvements

Operators now throw a compiler error when operating on undefined values

2 files changed, 513 insertions(+), 31 deletions(-)

src/ir.cpp+103-31
......@@ -10908,10 +10908,15 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1090810908 if (casted_op2 == ira->codegen->invalid_instruction)
1090910909 return ira->codegen->builtin_types.entry_invalid;
1091010910
10911 ConstExprValue *op1_val = &casted_op1->value;
10912 ConstExprValue *op2_val = &casted_op2->value;
10913 if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {
10911 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
1091410912 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
10913 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
10914 if (op1_val == nullptr)
10915 return ira->codegen->builtin_types.entry_invalid;
10916
10917 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
10918 if (op2_val == nullptr)
10919 return ira->codegen->builtin_types.entry_invalid;
1091510920
1091610921 assert(casted_op1->value.type->id == TypeTableEntryIdBool);
1091710922 assert(casted_op2->value.type->id == TypeTableEntryIdBool);
......@@ -11061,9 +11066,14 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1106111066 }
1106211067 }
1106311068
11064 ConstExprValue *op1_val = &op1->value;
11065 ConstExprValue *op2_val = &op2->value;
11066 if (value_is_comptime(op1_val) && value_is_comptime(op2_val)) {
11069 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
11070 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
11071 if (op1_val == nullptr)
11072 return ira->codegen->builtin_types.entry_invalid;
11073 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
11074 if (op2_val == nullptr)
11075 return ira->codegen->builtin_types.entry_invalid;
11076
1106711077 bool answer;
1106811078 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;
1106911079 if (op_id == IrBinOpCmpEq) {
......@@ -11152,10 +11162,15 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1115211162 if (casted_op2 == ira->codegen->invalid_instruction)
1115311163 return ira->codegen->builtin_types.entry_invalid;
1115411164
11155 ConstExprValue *op1_val = &casted_op1->value;
11156 ConstExprValue *op2_val = &casted_op2->value;
1115711165 bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type);
11158 if (one_possible_value || (value_is_comptime(op1_val) && value_is_comptime(op2_val))) {
11166 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {
11167 ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
11168 if (op1_val == nullptr)
11169 return ira->codegen->builtin_types.entry_invalid;
11170 ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
11171 if (op2_val == nullptr)
11172 return ira->codegen->builtin_types.entry_invalid;
11173
1115911174 bool answer;
1116011175 if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {
1116111176 Cmp cmp_result = float_cmp(op1_val, op2_val);
......@@ -11183,11 +11198,17 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1118311198 if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) {
1118411199 ConstExprValue *known_left_val;
1118511200 IrBinOp flipped_op_id;
11186 if (value_is_comptime(op1_val)) {
11187 known_left_val = op1_val;
11201 if (instr_is_comptime(casted_op1)) {
11202 known_left_val = ir_resolve_const(ira, casted_op1, UndefBad);
11203 if (known_left_val == nullptr)
11204 return ira->codegen->builtin_types.entry_invalid;
11205
1118811206 flipped_op_id = op_id;
11189 } else if (value_is_comptime(op2_val)) {
11190 known_left_val = op2_val;
11207 } else if (instr_is_comptime(casted_op2)) {
11208 known_left_val = ir_resolve_const(ira, casted_op2, UndefBad);
11209 if (known_left_val == nullptr)
11210 return ira->codegen->builtin_types.entry_invalid;
11211
1119111212 if (op_id == IrBinOpCmpLessThan) {
1119211213 flipped_op_id = IrBinOpCmpGreaterThan;
1119311214 } else if (op_id == IrBinOpCmpGreaterThan) {
......@@ -11459,8 +11480,14 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1145911480 }
1146011481
1146111482 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
11462 ConstExprValue *op1_val = &op1->value;
11463 ConstExprValue *op2_val = &casted_op2->value;
11483 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
11484 if (op1_val == nullptr)
11485 return ira->codegen->builtin_types.entry_invalid;
11486
11487 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
11488 if (op2_val == nullptr)
11489 return ira->codegen->builtin_types.entry_invalid;
11490
1146411491 IrInstruction *result_instruction = ir_get_const(ira, &bin_op_instruction->base);
1146511492 ir_link_new_instruction(result_instruction, &bin_op_instruction->base);
1146611493 ConstExprValue *out_val = &result_instruction->value;
......@@ -11539,7 +11566,15 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1153911566 if (is_signed_div) {
1154011567 bool ok = false;
1154111568 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
11542 if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) {
11569 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
11570 if (op1_val == nullptr)
11571 return ira->codegen->builtin_types.entry_invalid;
11572
11573 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
11574 if (op2_val == nullptr)
11575 return ira->codegen->builtin_types.entry_invalid;
11576
11577 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {
1154311578 // the division by zero error will be caught later, but we don't have a
1154411579 // division function ambiguity problem.
1154511580 op_id = IrBinOpDivTrunc;
......@@ -11547,8 +11582,8 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1154711582 } else {
1154811583 BigInt trunc_result;
1154911584 BigInt floor_result;
11550 bigint_div_trunc(&trunc_result, &op1->value.data.x_bigint, &op2->value.data.x_bigint);
11551 bigint_div_floor(&floor_result, &op1->value.data.x_bigint, &op2->value.data.x_bigint);
11585 bigint_div_trunc(&trunc_result, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
11586 bigint_div_floor(&floor_result, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
1155211587 if (bigint_cmp(&trunc_result, &floor_result) == CmpEQ) {
1155311588 ok = true;
1155411589 op_id = IrBinOpDivTrunc;
......@@ -11569,7 +11604,15 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1156911604 if (is_signed_div && (is_int || is_float)) {
1157011605 bool ok = false;
1157111606 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
11607 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
11608 if (op1_val == nullptr)
11609 return ira->codegen->builtin_types.entry_invalid;
11610
1157211611 if (is_int) {
11612 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
11613 if (op2_val == nullptr)
11614 return ira->codegen->builtin_types.entry_invalid;
11615
1157311616 if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) {
1157411617 // the division by zero error will be caught later, but we don't
1157511618 // have a remainder function ambiguity problem
......@@ -11577,14 +11620,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1157711620 } else {
1157811621 BigInt rem_result;
1157911622 BigInt mod_result;
11580 bigint_rem(&rem_result, &op1->value.data.x_bigint, &op2->value.data.x_bigint);
11581 bigint_mod(&mod_result, &op1->value.data.x_bigint, &op2->value.data.x_bigint);
11623 bigint_rem(&rem_result, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
11624 bigint_mod(&mod_result, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
1158211625 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
1158311626 }
1158411627 } else {
1158511628 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
1158611629 if (casted_op2 == ira->codegen->invalid_instruction)
1158711630 return ira->codegen->builtin_types.entry_invalid;
11631
11632 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
11633 if (op2_val == nullptr)
11634 return ira->codegen->builtin_types.entry_invalid;
11635
1158811636 if (float_cmp_zero(&casted_op2->value) == CmpEQ) {
1158911637 // the division by zero error will be caught later, but we don't
1159011638 // have a remainder function ambiguity problem
......@@ -11592,8 +11640,8 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1159211640 } else {
1159311641 ConstExprValue rem_result;
1159411642 ConstExprValue mod_result;
11595 float_rem(&rem_result, &op1->value, &casted_op2->value);
11596 float_mod(&mod_result, &op1->value, &casted_op2->value);
11643 float_rem(&rem_result, op1_val, op2_val);
11644 float_mod(&mod_result, op1_val, op2_val);
1159711645 ok = float_cmp(&rem_result, &mod_result) == CmpEQ;
1159811646 }
1159911647 }
......@@ -11651,8 +11699,13 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1165111699 return ira->codegen->builtin_types.entry_invalid;
1165211700
1165311701 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
11654 ConstExprValue *op1_val = &casted_op1->value;
11655 ConstExprValue *op2_val = &casted_op2->value;
11702 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
11703 if (op1_val == nullptr)
11704 return ira->codegen->builtin_types.entry_invalid;
11705 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
11706 if (op2_val == nullptr)
11707 return ira->codegen->builtin_types.entry_invalid;
11708
1165611709 IrInstruction *result_instruction = ir_get_const(ira, &bin_op_instruction->base);
1165711710 ir_link_new_instruction(result_instruction, &bin_op_instruction->base);
1165811711 ConstExprValue *out_val = &result_instruction->value;
......@@ -11827,9 +11880,16 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1182711880 out_val->data.x_ptr.data.base_array.array_val = out_array_val;
1182811881 out_val->data.x_ptr.data.base_array.elem_index = 0;
1182911882 }
11830 out_array_val->data.x_array.s_none.elements = create_const_vals(new_len);
1183111883
11884 if (op1_array_val->data.x_array.special == ConstArraySpecialUndef &&
11885 op2_array_val->data.x_array.special == ConstArraySpecialUndef) {
11886 out_array_val->data.x_array.special = ConstArraySpecialUndef;
11887 return result_type;
11888 }
11889
11890 out_array_val->data.x_array.s_none.elements = create_const_vals(new_len);
1183211891 expand_undef_array(ira->codegen, op1_array_val);
11892 expand_undef_array(ira->codegen, op2_array_val);
1183311893
1183411894 size_t next_index = 0;
1183511895 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
......@@ -11881,10 +11941,14 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
1188111941 }
1188211942
1188311943 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
11944 if (array_val->data.x_array.special == ConstArraySpecialUndef) {
11945 out_val->data.x_array.special = ConstArraySpecialUndef;
1188411946
11885 out_val->data.x_array.s_none.elements = create_const_vals(new_array_len);
11947 TypeTableEntry *child_type = array_type->data.array.child_type;
11948 return get_array_type(ira->codegen, child_type, new_array_len);
11949 }
1188611950
11887 expand_undef_array(ira->codegen, array_val);
11951 out_val->data.x_array.s_none.elements = create_const_vals(new_array_len);
1188811952
1188911953 uint64_t i = 0;
1189011954 for (uint64_t x = 0; x < mult_amt; x += 1) {
......@@ -13211,7 +13275,11 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
1321113275 // one of the ptr instructions
1321213276
1321313277 if (instr_is_comptime(value)) {
13214 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value);
13278 ConstExprValue *comptime_value = ir_resolve_const(ira, value, UndefBad);
13279 if (comptime_value == nullptr)
13280 return ira->codegen->builtin_types.entry_invalid;
13281
13282 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value);
1321513283 if (pointee->type == child_type) {
1321613284 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
1321713285 copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst);
......@@ -13328,7 +13396,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins
1332813396 if (expr_type->id == TypeTableEntryIdInt) {
1332913397 if (instr_is_comptime(value)) {
1333013398 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
13331 if (!target_const_val)
13399 if (target_const_val == nullptr)
1333213400 return ira->codegen->builtin_types.entry_invalid;
1333313401
1333413402 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -17908,9 +17976,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
1790817976 if (type_is_invalid(casted_value->value.type))
1790917977 return ira->codegen->builtin_types.entry_invalid;
1791017978
17911 if (casted_value->value.special != ConstValSpecialRuntime) {
17979 if (instr_is_comptime(casted_value)) {
17980 ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad);
17981 if (value == nullptr)
17982 return ira->codegen->builtin_types.entry_invalid;
17983
1791217984 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
17913 out_val->data.x_bool = !casted_value->value.data.x_bool;
17985 out_val->data.x_bool = !value->data.x_bool;
1791417986 return bool_type;
1791517987 }
1791617988
test/compile_errors.zig+410
......@@ -1905,6 +1905,416 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19051905 ".tmp_source.zig:1:15: error: use of undefined value",
19061906 );
19071907
1908 cases.add(
1909 "div on undefined value",
1910 \\comptime {
1911 \\ var a: i64 = undefined;
1912 \\ _ = a / a;
1913 \\}
1914 ,
1915 ".tmp_source.zig:3:9: error: use of undefined value",
1916 );
1917
1918 cases.add(
1919 "div assign on undefined value",
1920 \\comptime {
1921 \\ var a: i64 = undefined;
1922 \\ a /= a;
1923 \\}
1924 ,
1925 ".tmp_source.zig:3:5: error: use of undefined value",
1926 );
1927
1928 cases.add(
1929 "mod on undefined value",
1930 \\comptime {
1931 \\ var a: i64 = undefined;
1932 \\ _ = a % a;
1933 \\}
1934 ,
1935 ".tmp_source.zig:3:9: error: use of undefined value",
1936 );
1937
1938 cases.add(
1939 "mod assign on undefined value",
1940 \\comptime {
1941 \\ var a: i64 = undefined;
1942 \\ a %= a;
1943 \\}
1944 ,
1945 ".tmp_source.zig:3:5: error: use of undefined value",
1946 );
1947
1948 cases.add(
1949 "add on undefined value",
1950 \\comptime {
1951 \\ var a: i64 = undefined;
1952 \\ _ = a + a;
1953 \\}
1954 ,
1955 ".tmp_source.zig:3:9: error: use of undefined value",
1956 );
1957
1958 cases.add(
1959 "add assign on undefined value",
1960 \\comptime {
1961 \\ var a: i64 = undefined;
1962 \\ a += a;
1963 \\}
1964 ,
1965 ".tmp_source.zig:3:5: error: use of undefined value",
1966 );
1967
1968 cases.add(
1969 "add wrap on undefined value",
1970 \\comptime {
1971 \\ var a: i64 = undefined;
1972 \\ _ = a +% a;
1973 \\}
1974 ,
1975 ".tmp_source.zig:3:9: error: use of undefined value",
1976 );
1977
1978 cases.add(
1979 "add wrap assign on undefined value",
1980 \\comptime {
1981 \\ var a: i64 = undefined;
1982 \\ a +%= a;
1983 \\}
1984 ,
1985 ".tmp_source.zig:3:5: error: use of undefined value",
1986 );
1987
1988 cases.add(
1989 "sub on undefined value",
1990 \\comptime {
1991 \\ var a: i64 = undefined;
1992 \\ _ = a - a;
1993 \\}
1994 ,
1995 ".tmp_source.zig:3:9: error: use of undefined value",
1996 );
1997
1998 cases.add(
1999 "sub assign on undefined value",
2000 \\comptime {
2001 \\ var a: i64 = undefined;
2002 \\ a -= a;
2003 \\}
2004 ,
2005 ".tmp_source.zig:3:5: error: use of undefined value",
2006 );
2007
2008 cases.add(
2009 "sub wrap on undefined value",
2010 \\comptime {
2011 \\ var a: i64 = undefined;
2012 \\ _ = a -% a;
2013 \\}
2014 ,
2015 ".tmp_source.zig:3:9: error: use of undefined value",
2016 );
2017
2018 cases.add(
2019 "sub wrap assign on undefined value",
2020 \\comptime {
2021 \\ var a: i64 = undefined;
2022 \\ a -%= a;
2023 \\}
2024 ,
2025 ".tmp_source.zig:3:5: error: use of undefined value",
2026 );
2027
2028 cases.add(
2029 "mult on undefined value",
2030 \\comptime {
2031 \\ var a: i64 = undefined;
2032 \\ _ = a * a;
2033 \\}
2034 ,
2035 ".tmp_source.zig:3:9: error: use of undefined value",
2036 );
2037
2038 cases.add(
2039 "mult assign on undefined value",
2040 \\comptime {
2041 \\ var a: i64 = undefined;
2042 \\ a *= a;
2043 \\}
2044 ,
2045 ".tmp_source.zig:3:5: error: use of undefined value",
2046 );
2047
2048 cases.add(
2049 "mult wrap on undefined value",
2050 \\comptime {
2051 \\ var a: i64 = undefined;
2052 \\ _ = a *% a;
2053 \\}
2054 ,
2055 ".tmp_source.zig:3:9: error: use of undefined value",
2056 );
2057
2058 cases.add(
2059 "mult wrap assign on undefined value",
2060 \\comptime {
2061 \\ var a: i64 = undefined;
2062 \\ a *%= a;
2063 \\}
2064 ,
2065 ".tmp_source.zig:3:5: error: use of undefined value",
2066 );
2067
2068 cases.add(
2069 "shift left on undefined value",
2070 \\comptime {
2071 \\ var a: i64 = undefined;
2072 \\ _ = a << 2;
2073 \\}
2074 ,
2075 ".tmp_source.zig:3:9: error: use of undefined value",
2076 );
2077
2078 cases.add(
2079 "shift left assign on undefined value",
2080 \\comptime {
2081 \\ var a: i64 = undefined;
2082 \\ a <<= 2;
2083 \\}
2084 ,
2085 ".tmp_source.zig:3:5: error: use of undefined value",
2086 );
2087
2088 cases.add(
2089 "shift right on undefined value",
2090 \\comptime {
2091 \\ var a: i64 = undefined;
2092 \\ _ = a >> 2;
2093 \\}
2094 ,
2095 ".tmp_source.zig:3:9: error: use of undefined value",
2096 );
2097
2098 cases.add(
2099 "shift left assign on undefined value",
2100 \\comptime {
2101 \\ var a: i64 = undefined;
2102 \\ a >>= 2;
2103 \\}
2104 ,
2105 ".tmp_source.zig:3:5: error: use of undefined value",
2106 );
2107
2108 cases.add(
2109 "bin and on undefined value",
2110 \\comptime {
2111 \\ var a: i64 = undefined;
2112 \\ _ = a & a;
2113 \\}
2114 ,
2115 ".tmp_source.zig:3:9: error: use of undefined value",
2116 );
2117
2118 cases.add(
2119 "bin and assign on undefined value",
2120 \\comptime {
2121 \\ var a: i64 = undefined;
2122 \\ a &= a;
2123 \\}
2124 ,
2125 ".tmp_source.zig:3:5: error: use of undefined value",
2126 );
2127
2128 cases.add(
2129 "bin or on undefined value",
2130 \\comptime {
2131 \\ var a: i64 = undefined;
2132 \\ _ = a | a;
2133 \\}
2134 ,
2135 ".tmp_source.zig:3:9: error: use of undefined value",
2136 );
2137
2138 cases.add(
2139 "bin or assign on undefined value",
2140 \\comptime {
2141 \\ var a: i64 = undefined;
2142 \\ a |= a;
2143 \\}
2144 ,
2145 ".tmp_source.zig:3:5: error: use of undefined value",
2146 );
2147
2148 cases.add(
2149 "bin xor on undefined value",
2150 \\comptime {
2151 \\ var a: i64 = undefined;
2152 \\ _ = a ^ a;
2153 \\}
2154 ,
2155 ".tmp_source.zig:3:9: error: use of undefined value",
2156 );
2157
2158 cases.add(
2159 "bin xor assign on undefined value",
2160 \\comptime {
2161 \\ var a: i64 = undefined;
2162 \\ a ^= a;
2163 \\}
2164 ,
2165 ".tmp_source.zig:3:5: error: use of undefined value",
2166 );
2167
2168 cases.add(
2169 "equal on undefined value",
2170 \\comptime {
2171 \\ var a: i64 = undefined;
2172 \\ _ = a == a;
2173 \\}
2174 ,
2175 ".tmp_source.zig:3:9: error: use of undefined value",
2176 );
2177
2178 cases.add(
2179 "not equal on undefined value",
2180 \\comptime {
2181 \\ var a: i64 = undefined;
2182 \\ _ = a != a;
2183 \\}
2184 ,
2185 ".tmp_source.zig:3:9: error: use of undefined value",
2186 );
2187
2188 cases.add(
2189 "greater than on undefined value",
2190 \\comptime {
2191 \\ var a: i64 = undefined;
2192 \\ _ = a > a;
2193 \\}
2194 ,
2195 ".tmp_source.zig:3:9: error: use of undefined value",
2196 );
2197
2198 cases.add(
2199 "greater than equal on undefined value",
2200 \\comptime {
2201 \\ var a: i64 = undefined;
2202 \\ _ = a >= a;
2203 \\}
2204 ,
2205 ".tmp_source.zig:3:9: error: use of undefined value",
2206 );
2207
2208 cases.add(
2209 "less than on undefined value",
2210 \\comptime {
2211 \\ var a: i64 = undefined;
2212 \\ _ = a < a;
2213 \\}
2214 ,
2215 ".tmp_source.zig:3:9: error: use of undefined value",
2216 );
2217
2218 cases.add(
2219 "less than equal on undefined value",
2220 \\comptime {
2221 \\ var a: i64 = undefined;
2222 \\ _ = a <= a;
2223 \\}
2224 ,
2225 ".tmp_source.zig:3:9: error: use of undefined value",
2226 );
2227
2228 cases.add(
2229 "and on undefined value",
2230 \\comptime {
2231 \\ var a: bool = undefined;
2232 \\ _ = a and a;
2233 \\}
2234 ,
2235 ".tmp_source.zig:3:9: error: use of undefined value",
2236 );
2237
2238 cases.add(
2239 "or on undefined value",
2240 \\comptime {
2241 \\ var a: bool = undefined;
2242 \\ _ = a or a;
2243 \\}
2244 ,
2245 ".tmp_source.zig:3:9: error: use of undefined value",
2246 );
2247
2248 cases.add(
2249 "negate on undefined value",
2250 \\comptime {
2251 \\ var a: i64 = undefined;
2252 \\ _ = -a;
2253 \\}
2254 ,
2255 ".tmp_source.zig:3:10: error: use of undefined value",
2256 );
2257
2258 cases.add(
2259 "negate wrap on undefined value",
2260 \\comptime {
2261 \\ var a: i64 = undefined;
2262 \\ _ = -%a;
2263 \\}
2264 ,
2265 ".tmp_source.zig:3:11: error: use of undefined value",
2266 );
2267
2268 cases.add(
2269 "bin not on undefined value",
2270 \\comptime {
2271 \\ var a: i64 = undefined;
2272 \\ _ = ~a;
2273 \\}
2274 ,
2275 ".tmp_source.zig:3:10: error: use of undefined value",
2276 );
2277
2278 cases.add(
2279 "bool not on undefined value",
2280 \\comptime {
2281 \\ var a: bool = undefined;
2282 \\ _ = !a;
2283 \\}
2284 ,
2285 ".tmp_source.zig:3:10: error: use of undefined value",
2286 );
2287
2288 cases.add(
2289 "orelse on undefined value",
2290 \\comptime {
2291 \\ var a: ?bool = undefined;
2292 \\ _ = a orelse false;
2293 \\}
2294 ,
2295 ".tmp_source.zig:3:11: error: use of undefined value",
2296 );
2297
2298 cases.add(
2299 "catch on undefined value",
2300 \\comptime {
2301 \\ var a: error!bool = undefined;
2302 \\ _ = a catch |err| false;
2303 \\}
2304 ,
2305 ".tmp_source.zig:3:11: error: use of undefined value",
2306 );
2307
2308 cases.add(
2309 "deref on undefined value",
2310 \\comptime {
2311 \\ var a: *u8 = undefined;
2312 \\ _ = a.*;
2313 \\}
2314 ,
2315 ".tmp_source.zig:3:9: error: use of undefined value",
2316 );
2317
19082318 cases.add(
19092319 "endless loop in function evaluation",
19102320 \\const seventh_fib_number = fibbonaci(7);