diff --git a/spec/compiler/crystal/tools/expand_spec.cr b/spec/compiler/crystal/tools/expand_spec.cr index e8f9b770f3ec..4ebdfff6b836 100644 --- a/spec/compiler/crystal/tools/expand_spec.cr +++ b/spec/compiler/crystal/tools/expand_spec.cr @@ -157,7 +157,7 @@ describe "expand" do {% end %} CRYSTAL - assert_expand_simple code, "1\n2\n3\n" + assert_expand_simple code, "1\n\n2\n\n3\n" end it "expands macro control {% for %} with cursor inside it" do @@ -167,7 +167,7 @@ describe "expand" do {% end %} CRYSTAL - assert_expand_simple code, "1\n2\n3\n" + assert_expand_simple code, "1\n\n2\n\n3\n" end it "expands macro control {% for %} with cursor at end of it" do @@ -177,7 +177,7 @@ describe "expand" do ‸{% end %} CRYSTAL - assert_expand_simple code, "1\n2\n3\n" + assert_expand_simple code, "1\n\n2\n\n3\n" end it "expands macro control {% for %} with indent" do @@ -195,7 +195,7 @@ describe "expand" do {% end %} CRYSTAL - assert_expand_simple code, original: original, expanded: "1\n2\n3\n" + assert_expand_simple code, original: original, expanded: "1\n\n2\n\n3\n" end it "expands simple macro" do @@ -258,7 +258,7 @@ describe "expand" do ‸foo CRYSTAL - assert_expand_simple code, original: "foo", expanded: %("if true"\n"1"\n"2"\n"3"\n) + assert_expand_simple code, original: "foo", expanded: %("if true"\n\n\n"1"\n\n"2"\n\n"3"\n) end it "expands macros with 2 level" do @@ -615,6 +615,7 @@ describe "expand" do def hello_str "hello" end + # symbol of hello def hello_sym :hello diff --git a/spec/compiler/semantic/restrictions_augmenter_spec.cr b/spec/compiler/semantic/restrictions_augmenter_spec.cr index 2b7250658693..d77b61327f82 100644 --- a/spec/compiler/semantic/restrictions_augmenter_spec.cr +++ b/spec/compiler/semantic/restrictions_augmenter_spec.cr @@ -78,7 +78,9 @@ describe "Semantic: restrictions augmenter" do class Baz end end + @x : Bar::Baz + def initialize(value : ::Foo::Bar::Baz) @x = value end @@ -110,7 +112,9 @@ describe "Semantic: restrictions augmenter" do class Baz end end + @x : Bar::Baz + def initialize(value : Bar::Baz) @x = value end @@ -400,8 +404,10 @@ describe "Semantic: restrictions augmenter" do macro foo {{ yield }} end + class Foo end + class Bar @x : Foo def initialize(value : ::Foo) diff --git a/src/compiler/crystal/syntax/to_s.cr b/src/compiler/crystal/syntax/to_s.cr index 36c34cb045bb..ae3576051a87 100644 --- a/src/compiler/crystal/syntax/to_s.cr +++ b/src/compiler/crystal/syntax/to_s.cr @@ -236,11 +236,11 @@ module Crystal if @inside_macro > 0 node.expressions.each &.accept self else - last_node = node.expressions.first + last_node = nil node.expressions.each_with_index do |exp, i| unless exp.nop? - self.write_extra_newlines last_node.end_location, exp.location do + self.write_extra_newlines((last_node || exp).end_location, exp.location) do append_indent unless node.keyword.paren? && i == 0 exp.accept self newline unless node.keyword.paren? && i == node.expressions.size - 1