diff --git a/spec/compiler/interpreter/primitives_spec.cr b/spec/compiler/interpreter/primitives_spec.cr index 5a9f4c856952..21aad383a01c 100644 --- a/spec/compiler/interpreter/primitives_spec.cr +++ b/spec/compiler/interpreter/primitives_spec.cr @@ -316,7 +316,7 @@ describe Crystal::Repl::Interpreter do assert_overflows 1_i16 + 32767 assert_overflows 1_u32 + 4294967295 assert_overflows 1_i32 + 2147483647 - assert_overflows 1_u64 + 18446744073709551615 + assert_overflows 1_u64 + 18446744073709551615u64 assert_overflows 1_i64 + 9223372036854775807 end @@ -328,7 +328,7 @@ describe Crystal::Repl::Interpreter do assert_overflows 1_u32 - 2 assert_overflows 1_i32 - 2147483650 assert_overflows 1_u64 - 2 - assert_overflows 1_i64 - 9223372036854775810 + assert_overflows 1_i64 - 9223372036854775810u64 end context "*" do diff --git a/spec/compiler/macro/macro_methods_spec.cr b/spec/compiler/macro/macro_methods_spec.cr index eaa712936b83..7d949ae0932b 100644 --- a/spec/compiler/macro/macro_methods_spec.cr +++ b/spec/compiler/macro/macro_methods_spec.cr @@ -2949,6 +2949,10 @@ module Crystal assert_macro %({{parse_type :Foo }}), %(nil) end end + + it "exposes syntax warnings" do + assert_warning %({% parse_type "Foo(0x8000_0000_0000_0000)" %}), "Warning: 0x8000_0000_0000_0000 doesn't fit in an Int64, try using the suffix u64 or i128" + end end describe "printing" do diff --git a/spec/compiler/parser/warnings_spec.cr b/spec/compiler/parser/warnings_spec.cr new file mode 100644 index 000000000000..2bfb4ff937bc --- /dev/null +++ b/spec/compiler/parser/warnings_spec.cr @@ -0,0 +1,30 @@ +require "../../support/syntax" + +private def assert_parser_warning(source, message, *, file = __FILE__, line = __LINE__) + parser = Parser.new(source) + parser.filename = "/foo/bar/baz.cr" + node = parser.parse + + warnings = parser.warnings.infos + warnings.size.should eq(1), file: file, line: line + warnings[0].should contain(message), file: file, line: line +end + +describe "Parser warnings" do + it "warns on suffix-less UInt64 literals > Int64::MAX" do + values = [ + "9223372036854775808", # Int64::MAX + 1 + "9999999999999999999", + "10000000000000000000", + "18446744073709551615", # UInt64::MAX + "0x8000_0000_0000_0000", + "0xFFFF_FFFF_FFFF_FFFF", + ] + + values.each do |value| + assert_parser_warning value, "Warning: #{value} doesn't fit in an Int64, try using the suffix u64 or i128" + assert_parser_warning "Foo(#{value})", "Warning: #{value} doesn't fit in an Int64, try using the suffix u64 or i128" + assert_parser_warning "{{ #{value} }}", "Warning: #{value} doesn't fit in an Int64, try using the suffix u64 or i128" + end + end +end diff --git a/spec/compiler/semantic/warnings_spec.cr b/spec/compiler/semantic/warnings_spec.cr index fb0a915431ab..91634f95e1ec 100644 --- a/spec/compiler/semantic/warnings_spec.cr +++ b/spec/compiler/semantic/warnings_spec.cr @@ -761,4 +761,12 @@ describe "Semantic: warnings" do CR end end + + it "exposes syntax warnings" do + assert_warning UInt64::MAX.to_s, "Warning: #{UInt64::MAX} doesn't fit in an Int64, try using the suffix u64 or i128" + end + + it "exposes syntax warnings after macro interpolation" do + assert_warning "{% begin %}0x8000_0000_0000_000{{ 0 }}{% end %}", "Warning: 0x8000_0000_0000_0000 doesn't fit in an Int64, try using the suffix u64 or i128" + end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 9bf1b0ca05bb..69e3566e73e0 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -48,9 +48,10 @@ def assert_type(str, *, inject_primitives = false, flags = nil, file = __FILE__, end def semantic(code : String, wants_doc = false, inject_primitives = false, flags = nil, filename = nil) - node = parse(code, wants_doc: wants_doc, filename: filename) + warnings = WarningCollection.new + node = parse(code, wants_doc: wants_doc, filename: filename, warnings: warnings) node = inject_primitives(node) if inject_primitives - semantic node, wants_doc: wants_doc, flags: flags + semantic node, warnings: warnings, wants_doc: wants_doc, flags: flags end private def inject_primitives(node : ASTNode) @@ -66,8 +67,9 @@ private def inject_primitives(node : ASTNode) end end -def semantic(node : ASTNode, wants_doc = false, flags = nil) +def semantic(node : ASTNode, *, warnings = nil, wants_doc = false, flags = nil) program = new_program + program.warnings = warnings if warnings program.flags.concat(flags.split) if flags program.wants_doc = wants_doc node = program.normalize node @@ -139,7 +141,7 @@ end def assert_warning(code, message, *, file = __FILE__, line = __LINE__) warning_failures = warnings_result(code) warning_failures.size.should eq(1), file: file, line: line - warning_failures[0].should start_with(message), file: file, line: line + warning_failures[0].should contain(message), file: file, line: line end def assert_macro(macro_body, expected, args = nil, *, expected_pragmas = nil, flags = nil, file = __FILE__, line = __LINE__) diff --git a/spec/std/big/big_int_spec.cr b/spec/std/big/big_int_spec.cr index 1069e069af61..4aa7aaadcd6a 100644 --- a/spec/std/big/big_int_spec.cr +++ b/spec/std/big/big_int_spec.cr @@ -504,12 +504,12 @@ describe "BigInt" do big = BigInt.new("9" * 32) expect_raises(OverflowError) { big.to_i64 } expect_raises(OverflowError) { big.to_u64 } - big.to_i64!.should eq(-8814407033341083649) # 99999999999999999999999999999999 - 5421010862428*(2**64) - big.to_u64!.should eq(9632337040368467967) # 99999999999999999999999999999999 - 5421010862427*(2**64) + big.to_i64!.should eq(-8814407033341083649) # 99999999999999999999999999999999 - 5421010862428*(2**64) + big.to_u64!.should eq(9632337040368467967u64) # 99999999999999999999999999999999 - 5421010862427*(2**64) end it "between 63 and 64 bits" do - big = BigInt.new(i = 9999999999999999999) + big = BigInt.new(i = 9999999999999999999u64) expect_raises(OverflowError) { big.to_i64 } big.to_u64.should eq(i) big.to_i64!.should eq(-8446744073709551617) # 9999999999999999999 - 2**64 @@ -529,7 +529,7 @@ describe "BigInt" do big.to_i64.should eq(i) expect_raises(OverflowError) { big.to_u64 } big.to_i64!.should eq(i) - big.to_u64!.should eq(18446744073709541617) # -9999 + 2**64 + big.to_u64!.should eq(18446744073709541617u64) # -9999 + 2**64 end it "negative between 32 and 63 bits" do @@ -537,7 +537,7 @@ describe "BigInt" do big.to_i64.should eq(i) expect_raises(OverflowError) { big.to_u64 } big.to_i64!.should eq(i) - big.to_u64!.should eq(18446734073709551617) # -9999999999999 + 2**64 + big.to_u64!.should eq(18446734073709551617u64) # -9999999999999 + 2**64 end it "negative between 63 and 64 bits" do @@ -552,8 +552,8 @@ describe "BigInt" do big = BigInt.new("-" + "9" * 20) expect_raises(OverflowError) { big.to_i64 } expect_raises(OverflowError) { big.to_u64 } - big.to_i64!.should eq(-7766279631452241919) # -9999999999999999999 + 5*(2**64) - big.to_u64!.should eq(10680464442257309697) # -9999999999999999999 + 6*(2**64) + big.to_i64!.should eq(-7766279631452241919) # -9999999999999999999 + 5*(2**64) + big.to_u64!.should eq(10680464442257309697u64) # -9999999999999999999 + 6*(2**64) big = BigInt.new("-" + "9" * 32) expect_raises(OverflowError) { big.to_i64 } diff --git a/spec/std/crystal/compiler_rt/ashlti3_spec.cr b/spec/std/crystal/compiler_rt/ashlti3_spec.cr index 45176e801c59..2fe1780c2279 100644 --- a/spec/std/crystal/compiler_rt/ashlti3_spec.cr +++ b/spec/std/crystal/compiler_rt/ashlti3_spec.cr @@ -5,40 +5,40 @@ require "./spec_helper" # Ported from https://github.com/llvm/llvm-project/blob/ce59ccd04023cab3a837da14079ca2dcbfebb70c/compiler-rt/test/builtins/Unit/ashlti3_test.c it ".__ashlti3" do - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 0).should eq make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 1).should eq make_ti(0xFDB97530ECA8642B, 0xFDB97530ECA8642A) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 2).should eq make_ti(0xFB72EA61D950C857, 0xFB72EA61D950C854) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 3).should eq make_ti(0xF6E5D4C3B2A190AF, 0xF6E5D4C3B2A190A8) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 4).should eq make_ti(0xEDCBA9876543215F, 0xEDCBA98765432150) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 28).should eq make_ti(0x876543215FEDCBA9, 0x8765432150000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 29).should eq make_ti(0x0ECA8642BFDB9753, 0x0ECA8642A0000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 30).should eq make_ti(0x1D950C857FB72EA6, 0x1D950C8540000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 31).should eq make_ti(0x3B2A190AFF6E5D4C, 0x3B2A190A80000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 32).should eq make_ti(0x76543215FEDCBA98, 0x7654321500000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 33).should eq make_ti(0xECA8642BFDB97530, 0xECA8642A00000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 34).should eq make_ti(0xD950C857FB72EA61, 0xD950C85400000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 35).should eq make_ti(0xB2A190AFF6E5D4C3, 0xB2A190A800000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 36).should eq make_ti(0x6543215FEDCBA987, 0x6543215000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 60).should eq make_ti(0x5FEDCBA987654321, 0x5000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 61).should eq make_ti(0xBFDB97530ECA8642, 0xA000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 62).should eq make_ti(0x7FB72EA61D950C85, 0x4000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 63).should eq make_ti(0xFF6E5D4C3B2A190A, 0x8000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 64).should eq make_ti(0xFEDCBA9876543215, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 65).should eq make_ti(0xFDB97530ECA8642A, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 66).should eq make_ti(0xFB72EA61D950C854, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 67).should eq make_ti(0xF6E5D4C3B2A190A8, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 68).should eq make_ti(0xEDCBA98765432150, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 92).should eq make_ti(0x8765432150000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 93).should eq make_ti(0x0ECA8642A0000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 94).should eq make_ti(0x1D950C8540000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 95).should eq make_ti(0x3B2A190A80000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 96).should eq make_ti(0x7654321500000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 97).should eq make_ti(0xECA8642A00000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 98).should eq make_ti(0xD950C85400000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 99).should eq make_ti(0xB2A190A800000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 100).should eq make_ti(0x6543215000000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 124).should eq make_ti(0x5000000000000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 125).should eq make_ti(0xA000000000000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 126).should eq make_ti(0x4000000000000000, 0x0000000000000000) - __ashlti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 127).should eq make_ti(0x8000000000000000, 0x0000000000000000) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 0).should eq make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 1).should eq make_ti(0xFDB97530ECA8642Bu64, 0xFDB97530ECA8642Au64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 2).should eq make_ti(0xFB72EA61D950C857u64, 0xFB72EA61D950C854u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 3).should eq make_ti(0xF6E5D4C3B2A190AFu64, 0xF6E5D4C3B2A190A8u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 4).should eq make_ti(0xEDCBA9876543215Fu64, 0xEDCBA98765432150u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 28).should eq make_ti(0x876543215FEDCBA9u64, 0x8765432150000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 29).should eq make_ti(0x0ECA8642BFDB9753u64, 0x0ECA8642A0000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 30).should eq make_ti(0x1D950C857FB72EA6u64, 0x1D950C8540000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 31).should eq make_ti(0x3B2A190AFF6E5D4Cu64, 0x3B2A190A80000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 32).should eq make_ti(0x76543215FEDCBA98u64, 0x7654321500000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 33).should eq make_ti(0xECA8642BFDB97530u64, 0xECA8642A00000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 34).should eq make_ti(0xD950C857FB72EA61u64, 0xD950C85400000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 35).should eq make_ti(0xB2A190AFF6E5D4C3u64, 0xB2A190A800000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 36).should eq make_ti(0x6543215FEDCBA987u64, 0x6543215000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 60).should eq make_ti(0x5FEDCBA987654321u64, 0x5000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 61).should eq make_ti(0xBFDB97530ECA8642u64, 0xA000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 62).should eq make_ti(0x7FB72EA61D950C85u64, 0x4000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 63).should eq make_ti(0xFF6E5D4C3B2A190Au64, 0x8000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 64).should eq make_ti(0xFEDCBA9876543215u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 65).should eq make_ti(0xFDB97530ECA8642Au64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 66).should eq make_ti(0xFB72EA61D950C854u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 67).should eq make_ti(0xF6E5D4C3B2A190A8u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 68).should eq make_ti(0xEDCBA98765432150u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 92).should eq make_ti(0x8765432150000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 93).should eq make_ti(0x0ECA8642A0000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 94).should eq make_ti(0x1D950C8540000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 95).should eq make_ti(0x3B2A190A80000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 96).should eq make_ti(0x7654321500000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 97).should eq make_ti(0xECA8642A00000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 98).should eq make_ti(0xD950C85400000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 99).should eq make_ti(0xB2A190A800000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 100).should eq make_ti(0x6543215000000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 124).should eq make_ti(0x5000000000000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 125).should eq make_ti(0xA000000000000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 126).should eq make_ti(0x4000000000000000u64, 0x0000000000000000u64) + __ashlti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 127).should eq make_ti(0x8000000000000000u64, 0x0000000000000000u64) end diff --git a/spec/std/crystal/compiler_rt/ashrti3_spec.cr b/spec/std/crystal/compiler_rt/ashrti3_spec.cr index 6d593ff7918c..716892eca731 100644 --- a/spec/std/crystal/compiler_rt/ashrti3_spec.cr +++ b/spec/std/crystal/compiler_rt/ashrti3_spec.cr @@ -5,40 +5,40 @@ require "./spec_helper" # Ported from https://github.com/llvm/llvm-project/blob/ce59ccd04023cab3a837da14079ca2dcbfebb70c/compiler-rt/test/builtins/Unit/ashrti3_test.c it ".__ashrti3" do - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 0).should eq make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 1).should eq make_ti(0xFF6E5D4C3B2A190A, 0xFF6E5D4C3B2A190A) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 2).should eq make_ti(0xFFB72EA61D950C85, 0x7FB72EA61D950C85) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 3).should eq make_ti(0xFFDB97530ECA8642, 0xBFDB97530ECA8642) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 4).should eq make_ti(0xFFEDCBA987654321, 0x5FEDCBA987654321) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 28).should eq make_ti(0xFFFFFFFFEDCBA987, 0x6543215FEDCBA987) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 29).should eq make_ti(0xFFFFFFFFF6E5D4C3, 0xB2A190AFF6E5D4C3) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 30).should eq make_ti(0xFFFFFFFFFB72EA61, 0xD950C857FB72EA61) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 31).should eq make_ti(0xFFFFFFFFFDB97530, 0xECA8642BFDB97530) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 32).should eq make_ti(0xFFFFFFFFFEDCBA98, 0x76543215FEDCBA98) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 33).should eq make_ti(0xFFFFFFFFFF6E5D4C, 0x3B2A190AFF6E5D4C) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 34).should eq make_ti(0xFFFFFFFFFFB72EA6, 0x1D950C857FB72EA6) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 35).should eq make_ti(0xFFFFFFFFFFDB9753, 0x0ECA8642BFDB9753) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 36).should eq make_ti(0xFFFFFFFFFFEDCBA9, 0x876543215FEDCBA9) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 60).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xEDCBA9876543215F) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 61).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xF6E5D4C3B2A190AF) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 62).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFB72EA61D950C857) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 63).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFDB97530ECA8642B) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 64).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFEDCBA9876543215) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 65).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFF6E5D4C3B2A190A) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 66).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFB72EA61D950C85) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 67).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFDB97530ECA8642) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 68).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFEDCBA987654321) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 92).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFEDCBA987) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 93).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFF6E5D4C3) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 94).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFB72EA61) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 95).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFDB97530) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 96).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFEDCBA98) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 97).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFF6E5D4C) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 98).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFB72EA6) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 99).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFDB9753) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 100).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFEDCBA9) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 124).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 125).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 126).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) - __ashrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 127).should eq make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 0).should eq make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 1).should eq make_ti(0xFF6E5D4C3B2A190Au64, 0xFF6E5D4C3B2A190Au64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 2).should eq make_ti(0xFFB72EA61D950C85u64, 0x7FB72EA61D950C85u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 3).should eq make_ti(0xFFDB97530ECA8642u64, 0xBFDB97530ECA8642u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 4).should eq make_ti(0xFFEDCBA987654321u64, 0x5FEDCBA987654321u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 28).should eq make_ti(0xFFFFFFFFEDCBA987u64, 0x6543215FEDCBA987u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 29).should eq make_ti(0xFFFFFFFFF6E5D4C3u64, 0xB2A190AFF6E5D4C3u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 30).should eq make_ti(0xFFFFFFFFFB72EA61u64, 0xD950C857FB72EA61u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 31).should eq make_ti(0xFFFFFFFFFDB97530u64, 0xECA8642BFDB97530u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 32).should eq make_ti(0xFFFFFFFFFEDCBA98u64, 0x76543215FEDCBA98u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 33).should eq make_ti(0xFFFFFFFFFF6E5D4Cu64, 0x3B2A190AFF6E5D4Cu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 34).should eq make_ti(0xFFFFFFFFFFB72EA6u64, 0x1D950C857FB72EA6u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 35).should eq make_ti(0xFFFFFFFFFFDB9753u64, 0x0ECA8642BFDB9753u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 36).should eq make_ti(0xFFFFFFFFFFEDCBA9u64, 0x876543215FEDCBA9u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 60).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xEDCBA9876543215Fu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 61).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xF6E5D4C3B2A190AFu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 62).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFB72EA61D950C857u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 63).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFDB97530ECA8642Bu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 64).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFEDCBA9876543215u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 65).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFF6E5D4C3B2A190Au64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 66).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFB72EA61D950C85u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 67).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFDB97530ECA8642u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 68).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFEDCBA987654321u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 92).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFEDCBA987u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 93).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFF6E5D4C3u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 94).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFB72EA61u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 95).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFDB97530u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 96).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFEDCBA98u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 97).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFF6E5D4Cu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 98).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFB72EA6u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 99).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFDB9753u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 100).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFEDCBA9u64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 124).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 125).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 126).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64) + __ashrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 127).should eq make_ti(0xFFFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64) end diff --git a/spec/std/crystal/compiler_rt/divmod128_spec.cr b/spec/std/crystal/compiler_rt/divmod128_spec.cr index 88746f873138..db87bc46057e 100644 --- a/spec/std/crystal/compiler_rt/divmod128_spec.cr +++ b/spec/std/crystal/compiler_rt/divmod128_spec.cr @@ -68,16 +68,16 @@ describe "__udivti3" do test__udivti3(0, 1, 0) test__udivti3(2, 1, 2) - test__udivti3(make_tu(0x0, 0x8000000000000000), 1, make_tu(0x0, 0x8000000000000000)) - test__udivti3(make_tu(0x0, 0x8000000000000000), 2, make_tu(0x0, 0x4000000000000000)) - test__udivti3(make_tu(0xffffffffffffffff, 0xffffffffffffffff), 2, make_tu(0x7fffffffffffffff, 0xffffffffffffffff)) + test__udivti3(make_tu(0x0, 0x8000000000000000u64), 1, make_tu(0x0, 0x8000000000000000u64)) + test__udivti3(make_tu(0x0, 0x8000000000000000u64), 2, make_tu(0x0, 0x4000000000000000u64)) + test__udivti3(make_tu(0xffffffffffffffffu64, 0xffffffffffffffffu64), 2, make_tu(0x7fffffffffffffffu64, 0xffffffffffffffffu64)) end describe "__umodti3" do test__umodti3(0, 1, 0) test__umodti3(2, 1, 0) - test__umodti3(make_tu(0x0, 0x8000000000000000), 1, 0) - test__umodti3(make_tu(0x0, 0x8000000000000000), 2, 0) - test__umodti3(make_tu(0xffffffffffffffff, 0xffffffffffffffff), 2, 1) + test__umodti3(make_tu(0x0, 0x8000000000000000u64), 1, 0) + test__umodti3(make_tu(0x0, 0x8000000000000000u64), 2, 0) + test__umodti3(make_tu(0xffffffffffffffffu64, 0xffffffffffffffffu64), 2, 1) end diff --git a/spec/std/crystal/compiler_rt/lshrti3_spec.cr b/spec/std/crystal/compiler_rt/lshrti3_spec.cr index 61eab9fb4b0c..567e384f37f1 100644 --- a/spec/std/crystal/compiler_rt/lshrti3_spec.cr +++ b/spec/std/crystal/compiler_rt/lshrti3_spec.cr @@ -5,40 +5,40 @@ require "./spec_helper" # Ported from https://github.com/llvm/llvm-project/blob/ce59ccd04023cab3a837da14079ca2dcbfebb70c/compiler-rt/test/builtins/Unit/lshrti3_test.c it ".__lshrti3" do - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 0).should eq make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 1).should eq make_ti(0x7F6E5D4C3B2A190A, 0xFF6E5D4C3B2A190A) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 2).should eq make_ti(0x3FB72EA61D950C85, 0x7FB72EA61D950C85) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 3).should eq make_ti(0x1FDB97530ECA8642, 0xBFDB97530ECA8642) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 4).should eq make_ti(0x0FEDCBA987654321, 0x5FEDCBA987654321) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 28).should eq make_ti(0x0000000FEDCBA987, 0x6543215FEDCBA987) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 29).should eq make_ti(0x00000007F6E5D4C3, 0xB2A190AFF6E5D4C3) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 30).should eq make_ti(0x00000003FB72EA61, 0xD950C857FB72EA61) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 31).should eq make_ti(0x00000001FDB97530, 0xECA8642BFDB97530) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 32).should eq make_ti(0x00000000FEDCBA98, 0x76543215FEDCBA98) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 33).should eq make_ti(0x000000007F6E5D4C, 0x3B2A190AFF6E5D4C) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 34).should eq make_ti(0x000000003FB72EA6, 0x1D950C857FB72EA6) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 35).should eq make_ti(0x000000001FDB9753, 0x0ECA8642BFDB9753) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 36).should eq make_ti(0x000000000FEDCBA9, 0x876543215FEDCBA9) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 60).should eq make_ti(0x000000000000000F, 0xEDCBA9876543215F) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 61).should eq make_ti(0x0000000000000007, 0xF6E5D4C3B2A190AF) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 62).should eq make_ti(0x0000000000000003, 0xFB72EA61D950C857) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 63).should eq make_ti(0x0000000000000001, 0xFDB97530ECA8642B) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 64).should eq make_ti(0x0000000000000000, 0xFEDCBA9876543215) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 65).should eq make_ti(0x0000000000000000, 0x7F6E5D4C3B2A190A) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 66).should eq make_ti(0x0000000000000000, 0x3FB72EA61D950C85) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 67).should eq make_ti(0x0000000000000000, 0x1FDB97530ECA8642) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 68).should eq make_ti(0x0000000000000000, 0x0FEDCBA987654321) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 92).should eq make_ti(0x0000000000000000, 0x0000000FEDCBA987) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 93).should eq make_ti(0x0000000000000000, 0x00000007F6E5D4C3) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 94).should eq make_ti(0x0000000000000000, 0x00000003FB72EA61) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 95).should eq make_ti(0x0000000000000000, 0x00000001FDB97530) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 96).should eq make_ti(0x0000000000000000, 0x00000000FEDCBA98) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 97).should eq make_ti(0x0000000000000000, 0x000000007F6E5D4C) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 98).should eq make_ti(0x0000000000000000, 0x000000003FB72EA6) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 99).should eq make_ti(0x0000000000000000, 0x000000001FDB9753) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 100).should eq make_ti(0x0000000000000000, 0x000000000FEDCBA9) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 124).should eq make_ti(0x0000000000000000, 0x000000000000000F) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 125).should eq make_ti(0x0000000000000000, 0x0000000000000007) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 126).should eq make_ti(0x0000000000000000, 0x0000000000000003) - __lshrti3(make_ti(0xFEDCBA9876543215, 0xFEDCBA9876543215), 127).should eq make_ti(0x0000000000000000, 0x0000000000000001) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 0).should eq make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 1).should eq make_ti(0x7F6E5D4C3B2A190Au64, 0xFF6E5D4C3B2A190Au64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 2).should eq make_ti(0x3FB72EA61D950C85u64, 0x7FB72EA61D950C85u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 3).should eq make_ti(0x1FDB97530ECA8642u64, 0xBFDB97530ECA8642u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 4).should eq make_ti(0x0FEDCBA987654321u64, 0x5FEDCBA987654321u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 28).should eq make_ti(0x0000000FEDCBA987u64, 0x6543215FEDCBA987u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 29).should eq make_ti(0x00000007F6E5D4C3u64, 0xB2A190AFF6E5D4C3u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 30).should eq make_ti(0x00000003FB72EA61u64, 0xD950C857FB72EA61u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 31).should eq make_ti(0x00000001FDB97530u64, 0xECA8642BFDB97530u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 32).should eq make_ti(0x00000000FEDCBA98u64, 0x76543215FEDCBA98u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 33).should eq make_ti(0x000000007F6E5D4Cu64, 0x3B2A190AFF6E5D4Cu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 34).should eq make_ti(0x000000003FB72EA6u64, 0x1D950C857FB72EA6u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 35).should eq make_ti(0x000000001FDB9753u64, 0x0ECA8642BFDB9753u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 36).should eq make_ti(0x000000000FEDCBA9u64, 0x876543215FEDCBA9u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 60).should eq make_ti(0x000000000000000Fu64, 0xEDCBA9876543215Fu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 61).should eq make_ti(0x0000000000000007u64, 0xF6E5D4C3B2A190AFu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 62).should eq make_ti(0x0000000000000003u64, 0xFB72EA61D950C857u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 63).should eq make_ti(0x0000000000000001u64, 0xFDB97530ECA8642Bu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 64).should eq make_ti(0x0000000000000000u64, 0xFEDCBA9876543215u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 65).should eq make_ti(0x0000000000000000u64, 0x7F6E5D4C3B2A190Au64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 66).should eq make_ti(0x0000000000000000u64, 0x3FB72EA61D950C85u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 67).should eq make_ti(0x0000000000000000u64, 0x1FDB97530ECA8642u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 68).should eq make_ti(0x0000000000000000u64, 0x0FEDCBA987654321u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 92).should eq make_ti(0x0000000000000000u64, 0x0000000FEDCBA987u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 93).should eq make_ti(0x0000000000000000u64, 0x00000007F6E5D4C3u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 94).should eq make_ti(0x0000000000000000u64, 0x00000003FB72EA61u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 95).should eq make_ti(0x0000000000000000u64, 0x00000001FDB97530u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 96).should eq make_ti(0x0000000000000000u64, 0x00000000FEDCBA98u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 97).should eq make_ti(0x0000000000000000u64, 0x000000007F6E5D4Cu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 98).should eq make_ti(0x0000000000000000u64, 0x000000003FB72EA6u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 99).should eq make_ti(0x0000000000000000u64, 0x000000001FDB9753u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 100).should eq make_ti(0x0000000000000000u64, 0x000000000FEDCBA9u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 124).should eq make_ti(0x0000000000000000u64, 0x000000000000000Fu64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 125).should eq make_ti(0x0000000000000000u64, 0x0000000000000007u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 126).should eq make_ti(0x0000000000000000u64, 0x0000000000000003u64) + __lshrti3(make_ti(0xFEDCBA9876543215u64, 0xFEDCBA9876543215u64), 127).should eq make_ti(0x0000000000000000u64, 0x0000000000000001u64) end diff --git a/spec/std/crystal/compiler_rt/mulodi4_spec.cr b/spec/std/crystal/compiler_rt/mulodi4_spec.cr index be5a57516d23..c723380014e5 100644 --- a/spec/std/crystal/compiler_rt/mulodi4_spec.cr +++ b/spec/std/crystal/compiler_rt/mulodi4_spec.cr @@ -13,9 +13,9 @@ private def test__mulodi4(a : Int64, b : Int64, expected : Int64, expected_overf end end -private HEX_0_7FFFFFFFFFFFFFFF = 0x7FFFFFFFFFFFFFFF.to_i64! -private HEX_0_8000000000000001 = 0x8000000000000001.to_i64! -private HEX_0_8000000000000000 = 0x8000000000000000.to_i64! +private HEX_0_7FFFFFFFFFFFFFFF = 0x7FFFFFFFFFFFFFFFi64 +private HEX_0_8000000000000001 = 0x8000000000000001u64.to_i64! +private HEX_0_8000000000000000 = 0x8000000000000000u64.to_i64! describe "__mulodi4" do test__mulodi4(0, 0, 0, 0) diff --git a/spec/std/crystal/compiler_rt/muloti4_spec.cr b/spec/std/crystal/compiler_rt/muloti4_spec.cr index ed52925ee8f9..62215f73ff95 100644 --- a/spec/std/crystal/compiler_rt/muloti4_spec.cr +++ b/spec/std/crystal/compiler_rt/muloti4_spec.cr @@ -50,96 +50,96 @@ describe "__muloti4" do test__muloti4(2097152, -4398046511103, -9223372036852678656, 0) test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0) test__muloti4(make_ti(0x00000000000000B5, 0x04F333F9DE5BE000), - make_ti(0x0000000000000000, 0x00B504F333F9DE5B), - make_ti(0x7FFFFFFFFFFFF328, 0xDF915DA296E8A000), 0) - test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + make_ti(0x0000000000000000u64, 0x00B504F333F9DE5Bu64), + make_ti(0x7FFFFFFFFFFFF328u64, 0xDF915DA296E8A000u64), 0) + test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), -2, - make_ti(0x8000000000000000, 0x0000000000000001), 1) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) test__muloti4(-2, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), - make_ti(0x8000000000000000, 0x0000000000000001), 1) - test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) + test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), -1, - make_ti(0x8000000000000000, 0x0000000000000001), 0) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0) test__muloti4(-1, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), - make_ti(0x8000000000000000, 0x0000000000000001), 0) - test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0) + test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0, 0, 0) test__muloti4(0, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0, 0) - test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 1, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0) test__muloti4(1, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) - test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0) + test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 2, - make_ti(0x8000000000000000, 0x0000000000000001), 1) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) test__muloti4(2, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), - make_ti(0x8000000000000000, 0x0000000000000001), 1) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000000u64), -2, - make_ti(0x8000000000000000, 0x0000000000000000), 1) + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) test__muloti4(-2, - make_ti(0x8000000000000000, 0x0000000000000000), - make_ti(0x8000000000000000, 0x0000000000000000), 1) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000000u64), -1, - make_ti(0x8000000000000000, 0x0000000000000000), 1) + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) test__muloti4(-1, - make_ti(0x8000000000000000, 0x0000000000000000), - make_ti(0x8000000000000000, 0x0000000000000000), 1) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000000u64), 0, 0, 0) test__muloti4(0, - make_ti(0x8000000000000000, 0x0000000000000000), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 0, 0) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1, - make_ti(0x8000000000000000, 0x0000000000000000), 0) + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 0) test__muloti4(1, - make_ti(0x8000000000000000, 0x0000000000000000), - make_ti(0x8000000000000000, 0x0000000000000000), 0) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 0) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000000u64), 2, - make_ti(0x8000000000000000, 0x0000000000000000), 1) + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) test__muloti4(2, - make_ti(0x8000000000000000, 0x0000000000000000), - make_ti(0x8000000000000000, 0x0000000000000000), 1) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000001u64), -2, - make_ti(0x8000000000000000, 0x0000000000000001), 1) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) test__muloti4(-2, - make_ti(0x8000000000000000, 0x0000000000000001), - make_ti(0x8000000000000000, 0x0000000000000001), 1) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000001u64), -1, - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0) test__muloti4(-1, - make_ti(0x8000000000000000, 0x0000000000000001), - make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), + make_ti(0x7FFFFFFFFFFFFFFFu64, 0xFFFFFFFFFFFFFFFFu64), 0) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0, 0, 0) test__muloti4(0, - make_ti(0x8000000000000000, 0x0000000000000001), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0, 0) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000001u64), 1, - make_ti(0x8000000000000000, 0x0000000000000001), 0) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0) test__muloti4(1, - make_ti(0x8000000000000000, 0x0000000000000001), - make_ti(0x8000000000000000, 0x0000000000000001), 0) - test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), + make_ti(0x8000000000000000u64, 0x0000000000000001u64), 0) + test__muloti4(make_ti(0x8000000000000000u64, 0x0000000000000001u64), 2, - make_ti(0x8000000000000000, 0x0000000000000000), 1) + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) test__muloti4(2, - make_ti(0x8000000000000000, 0x0000000000000001), - make_ti(0x8000000000000000, 0x0000000000000000), 1) + make_ti(0x8000000000000000u64, 0x0000000000000001u64), + make_ti(0x8000000000000000u64, 0x0000000000000000u64), 1) end diff --git a/spec/std/crystal/compiler_rt/multi3_spec.cr b/spec/std/crystal/compiler_rt/multi3_spec.cr index 7e93e3efce1d..3c3c8eae7070 100644 --- a/spec/std/crystal/compiler_rt/multi3_spec.cr +++ b/spec/std/crystal/compiler_rt/multi3_spec.cr @@ -48,5 +48,5 @@ it ".__multi3" do __multi3( make_ti(0x00000000000000B5, 0x04F333F9DE5BE000), make_ti(0x0000000000000000, 0x00B504F333F9DE5B) - ).should eq make_ti(0x7FFFFFFFFFFFF328, 0xDF915DA296E8A000) + ).should eq make_ti(0x7FFFFFFFFFFFF328u64, 0xDF915DA296E8A000u64) end diff --git a/spec/std/float_printer/diy_fp_spec.cr b/spec/std/float_printer/diy_fp_spec.cr index 560e4db13e7f..cfaee9de64d0 100644 --- a/spec/std/float_printer/diy_fp_spec.cr +++ b/spec/std/float_printer/diy_fp_spec.cr @@ -41,7 +41,7 @@ describe DiyFP do end it "multiply" do - fp1 = DiyFP.new(0x8000000000000000, 11) + fp1 = DiyFP.new(0x8000000000000000_u64, 11) fp2 = DiyFP.new(2_u64, 13) prod = fp1 * fp2 @@ -163,7 +163,7 @@ describe DiyFP do fp.exp.should eq -0x3FF - 52 + 1 - 63 # This is a denormal; so no hidden bit - fp.frac.should eq 0x8000000000000000 + fp.frac.should eq 0x8000000000000000_u64 end it "normalizes max f64" do diff --git a/spec/std/random_spec.cr b/spec/std/random_spec.cr index 5adb283b3b7c..37b951c89def 100644 --- a/spec/std/random_spec.cr +++ b/spec/std/random_spec.cr @@ -180,7 +180,7 @@ describe "Random" do it "allows creating a new default random with a seed" do values = Array.new(2) do rand = Random.new(1234) - {rand.rand, rand.rand(0xffffffffffffffff), rand.rand(2), rand.rand(-5i8..5i8)} + {rand.rand, rand.rand(0xffffffffffffffffu64), rand.rand(2), rand.rand(-5i8..5i8)} end values[0].should eq values[1] diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr index 780d5c27a175..55023929d00b 100644 --- a/spec/std/string_spec.cr +++ b/spec/std/string_spec.cr @@ -390,12 +390,12 @@ describe "String" do end describe "to_u64" do - it { "18446744073709551615".to_u64.should eq(18446744073709551615) } + it { "18446744073709551615".to_u64.should eq(18446744073709551615u64) } it { "0".to_u64.should eq(0) } it { expect_raises(ArgumentError) { "18446744073709551616".to_u64 } } it { expect_raises(ArgumentError) { "-1".to_u64 } } - it { "18446744073709551615".to_u64?.should eq(18446744073709551615) } + it { "18446744073709551615".to_u64?.should eq(18446744073709551615u64) } it { "18446744073709551616".to_u64?.should be_nil } it { "18446744073709551616".to_u64 { 0 }.should eq(0) } end diff --git a/spec/support/syntax.cr b/spec/support/syntax.cr index 5514fc1d4acf..e1fd8f43d951 100644 --- a/spec/support/syntax.cr +++ b/spec/support/syntax.cr @@ -158,8 +158,9 @@ def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = end end -def parse(string, wants_doc = false, filename = nil) - parser = Parser.new(string) +def parse(string, wants_doc = false, filename = nil, warnings = nil) + parser = Parser.new(string, warnings: warnings) + parser.warnings = warnings if warnings parser.wants_doc = wants_doc if filename parser.filename = filename diff --git a/src/big/big_decimal.cr b/src/big/big_decimal.cr index 0edabd7c18c4..66945bcc6899 100644 --- a/src/big/big_decimal.cr +++ b/src/big/big_decimal.cr @@ -704,7 +704,7 @@ struct Int # Converts `self` to `BigDecimal`. # ``` # require "big" - # 12123415151254124124.to_big_d + # 123456789012345678.to_big_d # ``` def to_big_d : BigDecimal BigDecimal.new(self) diff --git a/src/compiler/crystal/codegen/codegen.cr b/src/compiler/crystal/codegen/codegen.cr index 1bbf9670bfd7..5dca53131d67 100644 --- a/src/compiler/crystal/codegen/codegen.cr +++ b/src/compiler/crystal/codegen/codegen.cr @@ -18,7 +18,7 @@ module Crystal class Program def run(code, filename = nil, debug = Debug::Default) - parser = Parser.new(code) + parser = new_parser(code) parser.filename = filename node = parser.parse node = normalize node diff --git a/src/compiler/crystal/command/format.cr b/src/compiler/crystal/command/format.cr index a4c4bfdab467..76ebe9c3ef34 100644 --- a/src/compiler/crystal/command/format.cr +++ b/src/compiler/crystal/command/format.cr @@ -155,7 +155,7 @@ class Crystal::Command # This method is for mocking `Crystal.format` in test. private def format(filename, source) - Crystal.format(source, filename: filename) + Crystal.format(source, filename: filename, report_warnings: STDERR) end private def error(msg) diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 8b402e542fa4..0d99635497a7 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -230,7 +230,7 @@ module Crystal end private def parse(program, source : Source) - parser = Parser.new(source.code, program.string_pool) + parser = program.new_parser(source.code) parser.filename = source.filename parser.wants_doc = wants_doc? parser.parse diff --git a/src/compiler/crystal/interpreter/prompt.cr b/src/compiler/crystal/interpreter/prompt.cr index 6ab6a1bea055..ea6077cc4aa5 100644 --- a/src/compiler/crystal/interpreter/prompt.cr +++ b/src/compiler/crystal/interpreter/prompt.cr @@ -78,6 +78,8 @@ class Crystal::Repl::Prompt @line_number += 1 @incomplete = false + parser.warnings.report(STDOUT) + node rescue ex : Crystal::SyntaxException # TODO: improve this diff --git a/src/compiler/crystal/interpreter/repl.cr b/src/compiler/crystal/interpreter/repl.cr index cb0faa82a2c4..1a07333064a7 100644 --- a/src/compiler/crystal/interpreter/repl.cr +++ b/src/compiler/crystal/interpreter/repl.cr @@ -127,9 +127,12 @@ class Crystal::Repl end private def parse_code(code, filename = "") - parser = Parser.new code, @program.string_pool + warnings = @program.warnings.dup + warnings.infos = [] of String + parser = Parser.new code, @program.string_pool, warnings: warnings parser.filename = filename parsed_nodes = parser.parse + warnings.report(STDOUT) @program.normalize(parsed_nodes, inside_exp: false) end diff --git a/src/compiler/crystal/macros/macros.cr b/src/compiler/crystal/macros/macros.cr index ff5e8064f965..e088f477f803 100644 --- a/src/compiler/crystal/macros/macros.cr +++ b/src/compiler/crystal/macros/macros.cr @@ -36,7 +36,7 @@ class Crystal::Program def parse_macro_source(generated_source, macro_expansion_pragmas, the_macro, node, vars, current_def = nil, inside_type = false, inside_exp = false, visibility : Visibility = :public) begin - parser = Parser.new(generated_source, @program.string_pool, [vars.dup]) + parser = @program.new_parser(generated_source, var_scopes: [vars.dup]) parser.filename = VirtualFile.new(the_macro, generated_source, node.location) parser.macro_expansion_pragmas = macro_expansion_pragmas parser.visibility = visibility diff --git a/src/compiler/crystal/macros/methods.cr b/src/compiler/crystal/macros/methods.cr index 83cd8f910d63..115b771a399a 100644 --- a/src/compiler/crystal/macros/methods.cr +++ b/src/compiler/crystal/macros/methods.cr @@ -170,7 +170,7 @@ module Crystal arg.raise "argument to parse_type cannot be an empty value" if type_name.blank? begin - parser = Crystal::Parser.new type_name + parser = @program.new_parser type_name parser.next_token type = parser.parse_bare_proc_type parser.check :EOF diff --git a/src/compiler/crystal/program.cr b/src/compiler/crystal/program.cr index 30c1870e5396..55673ecc38f8 100644 --- a/src/compiler/crystal/program.cr +++ b/src/compiler/crystal/program.cr @@ -248,6 +248,12 @@ module Crystal define_macro_types end + # Returns a new `Parser` for the given *source*, sharing the string pool and + # warnings with this program. + def new_parser(source : String, var_scopes = [Set(String).new]) + Parser.new(source, string_pool, var_scopes, warnings) + end + # Returns a `LiteralExpander` useful to expand literal like arrays and hashes # into simpler forms. getter(literal_expander) { LiteralExpander.new self } diff --git a/src/compiler/crystal/semantic/semantic_visitor.cr b/src/compiler/crystal/semantic/semantic_visitor.cr index 5a7c900696ac..88164a36f914 100644 --- a/src/compiler/crystal/semantic/semantic_visitor.cr +++ b/src/compiler/crystal/semantic/semantic_visitor.cr @@ -51,7 +51,7 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor nodes = Array(ASTNode).new(filenames.size) filenames.each do |filename| if @program.requires.add?(filename) - parser = Parser.new File.read(filename), @program.string_pool + parser = @program.new_parser(File.read(filename)) parser.filename = filename parser.wants_doc = @program.wants_doc? parsed_nodes = parser.parse diff --git a/src/compiler/crystal/syntax/exception.cr b/src/compiler/crystal/syntax/exception.cr index c906b22c8b1d..3bc3591de017 100644 --- a/src/compiler/crystal/syntax/exception.cr +++ b/src/compiler/crystal/syntax/exception.cr @@ -34,7 +34,6 @@ module Crystal def append_to_s(io : IO, source) msg = @message.to_s error_message_lines = msg.lines - default_message = "syntax error in #{@filename}:#{@line_number}" io << error_body(source, default_message) io << '\n' @@ -42,6 +41,12 @@ module Crystal io << remaining error_message_lines end + def default_message + if (filename = @filename) && (line_number = @line_number) + "#{@warning ? "warning" : "syntax error"} in #{filename}:#{line_number}" + end + end + def to_s_with_source(io : IO, source) append_to_s io, source end diff --git a/src/compiler/crystal/syntax/lexer.cr b/src/compiler/crystal/syntax/lexer.cr index a6cc0f58b495..7f754e6fe5a7 100644 --- a/src/compiler/crystal/syntax/lexer.cr +++ b/src/compiler/crystal/syntax/lexer.cr @@ -1,6 +1,7 @@ require "./token" require "../exception" require "string_pool" +require "../warnings" module Crystal class Lexer @@ -52,7 +53,11 @@ module Crystal end end - def initialize(string, string_pool : StringPool? = nil) + # Warning settings and all detected warnings. + property warnings : WarningCollection + + def initialize(string, string_pool : StringPool? = nil, warnings : WarningCollection? = nil) + @warnings = warnings || WarningCollection.new @reader = Char::Reader.new(string) @token = Token.new @temp_token = Token.new @@ -1473,6 +1478,10 @@ module Crystal raise "#{string_range(start, pos_before_suffix)} doesn't fit in an #{type}, try using the suffix #{alternative}", @token, (current_pos - start) end + def warn_large_uint64_literal(start, pos_before_suffix) + @warnings.add_warning_at(@token.location, "#{string_range(start, pos_before_suffix)} doesn't fit in an Int64, try using the suffix u64 or i128") + end + private def scan_number(start, negative = false) @token.type = :NUMBER base = 10 @@ -1584,12 +1593,17 @@ module Crystal elsif negative raise_value_doesnt_fit_in(Int64, start, pos_before_suffix, "i128") else + warn_large_uint64_literal(start, pos_before_suffix) NumberKind::U64 end when 20 raise_value_doesnt_fit_in(Int64, start, pos_before_suffix, "i128") if negative - raise_value_doesnt_fit_in(UInt64, start, pos_before_suffix, "i128") unless raw_number_string.to_u64? - NumberKind::U64 + if raw_number_string.to_u64? + warn_large_uint64_literal(start, pos_before_suffix) + NumberKind::U64 + else + raise_value_doesnt_fit_in(UInt64, start, pos_before_suffix, "i128") + end when 21..38 raise_value_doesnt_fit_in(negative ? Int64 : UInt64, start, pos_before_suffix, "i128") when 39 diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index cb3f6b19ca88..48e45bbf3296 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -24,8 +24,8 @@ module Crystal new(str, string_pool, var_scopes).parse end - def initialize(str, string_pool : StringPool? = nil, @var_scopes = [Set(String).new]) - super(str, string_pool) + def initialize(str, string_pool : StringPool? = nil, @var_scopes = [Set(String).new], warnings : WarningCollection? = nil) + super(str, string_pool, warnings) @unclosed_stack = [] of Unclosed @calls_super = false @calls_initialize = false diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 3c5269a65584..64b6814270c9 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -1,16 +1,22 @@ require "../syntax" module Crystal - def self.format(source, filename = nil) - Crystal::Formatter.format(source, filename: filename) + def self.format(source, filename = nil, report_warnings : IO? = nil) + Crystal::Formatter.format(source, filename: filename, report_warnings: report_warnings) end class Formatter < Visitor - def self.format(source, filename = nil) + def self.format(source, filename = nil, report_warnings : IO? = nil) parser = Parser.new(source) parser.filename = filename nodes = parser.parse + # the formatter merely parses the same source again, it shouldn't + # introduce any new syntax warnings the parser cannot find + if report_warnings + parser.warnings.report(report_warnings) + end + formatter = new(source) formatter.skip_space_or_newline nodes.accept formatter diff --git a/src/compiler/crystal/tools/playground/server.cr b/src/compiler/crystal/tools/playground/server.cr index cc535f1609d7..4b8ee5f160a2 100644 --- a/src/compiler/crystal/tools/playground/server.cr +++ b/src/compiler/crystal/tools/playground/server.cr @@ -16,6 +16,7 @@ module Crystal::Playground end def self.instrument_and_prelude(session_key, port, tag, source, host : String? = "localhost") + # TODO: figure out how syntax warnings should be reported ast = Parser.new(source).parse instrumented = Playground::AgentInstrumentorTransformer.transform(ast).to_s diff --git a/src/int.cr b/src/int.cr index e4e9aa452963..7ad4c39daaef 100644 --- a/src/int.cr +++ b/src/int.cr @@ -6,8 +6,8 @@ # # An integer literal is an optional `+` or `-` sign, followed by # a sequence of digits and underscores, optionally followed by a suffix. -# If no suffix is present, the literal's type is the lowest between `Int32`, `Int64` and `UInt64` -# in which the number fits: +# If no suffix is present, the literal's type is `Int32`, or `Int64` if the +# number doesn't fit into an `Int32`: # # ``` # 1 # Int32 @@ -25,10 +25,14 @@ # +10 # Int32 # -20 # Int32 # -# 2147483648 # Int64 -# 9223372036854775808 # UInt64 +# 2147483648 # Int64 # ``` # +# Literals without a suffix that are larger than `Int64::MAX` represent a +# `UInt64` if the number fits, e.g. `9223372036854775808` and +# `0x80000000_00000000`. This behavior is deprecated and will become an error in +# the future. +# # The underscore `_` before the suffix is optional. # # Underscores can be used to make some numbers more readable: diff --git a/src/string.cr b/src/string.cr index 1823c0cd9139..a9eba0dc9d1b 100644 --- a/src/string.cr +++ b/src/string.cr @@ -459,7 +459,7 @@ class String # Same as `#to_i` but returns an `Int64` or the block's value. def to_i64(base : Int = 10, whitespace : Bool = true, underscore : Bool = false, prefix : Bool = false, strict : Bool = true, leading_zero_is_octal : Bool = false, &block) - gen_to_ Int64, UInt64, 9223372036854775807, 9223372036854775808 + gen_to_ Int64, UInt64, 9223372036854775807, 9223372036854775808u64 end # Same as `#to_i` but returns an `UInt64`.