From 81bc1c5a92f7ef8abafd15f61421cb4c63cf8dfa Mon Sep 17 00:00:00 2001 From: r00ster Date: Sat, 1 Dec 2018 14:58:43 +0100 Subject: [PATCH 1/7] Improve 2 error messages --- spec/compiler/semantic/tuple_spec.cr | 2 +- src/compiler/crystal/semantic/bindings.cr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index 3d2310e89147..b74d7e82b220 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -287,7 +287,7 @@ describe "Semantic: tuples" do pos += {0, 0} end ), - "tuple too big" + "tuple size cannot be greater than 300" end it "doesn't unify tuple metaclasses (#5384)" do diff --git a/src/compiler/crystal/semantic/bindings.cr b/src/compiler/crystal/semantic/bindings.cr index a6b0021b1cfd..390b61e69f01 100644 --- a/src/compiler/crystal/semantic/bindings.cr +++ b/src/compiler/crystal/semantic/bindings.cr @@ -519,7 +519,7 @@ module Crystal end if types.size > 300 - raise "tuple too big: Tuple(#{types[0...10].join(',')}, ...)" + raise "tuple size cannot be greater than 300 (size is #{types.size})" end self.type = tuple_type @@ -543,7 +543,7 @@ module Crystal end if entries.size > 300 - raise "named tuple too big: #{named_tuple_type}" + raise "named tuple size cannot be greater than 300 (size is #{entries.size})" end self.type = named_tuple_type From d4545b34e5c4c04de9a649c1cfe9598ad3f8dea9 Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Sat, 1 Dec 2018 19:09:25 +0100 Subject: [PATCH 2/7] Add named tuple spec --- spec/compiler/semantic/tuple_spec.cr | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index b74d7e82b220..998faee71d23 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -290,6 +290,17 @@ describe "Semantic: tuples" do "tuple size cannot be greater than 300" end + it "errors on named tuple too big" do + assert_error %( + { #{String.build do |io| + 301.times do |i| + io << "arg" << i << ": 0, " + end + end} } + ), + "named tuple size cannot be greater than 300" + end + it "doesn't unify tuple metaclasses (#5384)" do assert_type(%( Tuple(Int32) || Tuple(String) From c034bf32abf6336749552bfa346fa9c70b849dfe Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Mon, 31 Dec 2018 12:53:32 +0100 Subject: [PATCH 3/7] Make the error messages in specs complete --- spec/compiler/semantic/tuple_spec.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index 998faee71d23..61ffe5a257b6 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -283,11 +283,11 @@ describe "Semantic: tuples" do require "prelude" pos = {0, 0} - while true + 301.times do pos += {0, 0} end ), - "tuple size cannot be greater than 300" + "tuple size cannot be greater than 300 (size is 301)" end it "errors on named tuple too big" do @@ -298,7 +298,7 @@ describe "Semantic: tuples" do end end} } ), - "named tuple size cannot be greater than 300" + "named tuple size cannot be greater than 300 (size is 301)" end it "doesn't unify tuple metaclasses (#5384)" do From b2c4f4a6700af100336def5c3a92bac4b757770b Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Mon, 31 Dec 2018 14:41:54 +0100 Subject: [PATCH 4/7] Use while true --- spec/compiler/semantic/tuple_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index 61ffe5a257b6..45fc8bfaf45d 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -283,7 +283,7 @@ describe "Semantic: tuples" do require "prelude" pos = {0, 0} - 301.times do + while true pos += {0, 0} end ), From 1c33d77c781e32a9868138e691902b7fedf1c45c Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Mon, 31 Dec 2018 14:48:31 +0100 Subject: [PATCH 5/7] Make the times a bit higher --- spec/compiler/semantic/tuple_spec.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index 45fc8bfaf45d..f635d787b1ed 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -293,12 +293,12 @@ describe "Semantic: tuples" do it "errors on named tuple too big" do assert_error %( { #{String.build do |io| - 301.times do |i| + 333.times do |i| io << "arg" << i << ": 0, " end end} } ), - "named tuple size cannot be greater than 300 (size is 301)" + "named tuple size cannot be greater than 300 (size is 333)" end it "doesn't unify tuple metaclasses (#5384)" do From b74e208cd7595ce23a54b3fca92db229814f7500 Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Tue, 1 Jan 2019 20:19:55 +0100 Subject: [PATCH 6/7] Put named tuple's keys in variable --- spec/compiler/semantic/tuple_spec.cr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index f635d787b1ed..1ae8194f9874 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -291,12 +291,12 @@ describe "Semantic: tuples" do end it "errors on named tuple too big" do + named_tuple_keys = String.build do |io| + 333.times { |i| io << "key" << i << ": 0, " } + end + assert_error %( - { #{String.build do |io| - 333.times do |i| - io << "arg" << i << ": 0, " - end - end} } + { #{named_tuple_keys} } ), "named tuple size cannot be greater than 300 (size is 333)" end From b8e13aaf1c77edf9cb577390edc719fd74dec9ef Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Wed, 2 Jan 2019 19:52:26 +0100 Subject: [PATCH 7/7] Fix specs --- spec/compiler/semantic/tuple_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/compiler/semantic/tuple_spec.cr b/spec/compiler/semantic/tuple_spec.cr index 1ae8194f9874..59bed38167b3 100644 --- a/spec/compiler/semantic/tuple_spec.cr +++ b/spec/compiler/semantic/tuple_spec.cr @@ -287,7 +287,7 @@ describe "Semantic: tuples" do pos += {0, 0} end ), - "tuple size cannot be greater than 300 (size is 301)" + "tuple size cannot be greater than 300 (size is 302)" end it "errors on named tuple too big" do