Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 788e06955aad
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3ca5428098e3
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 17, 2017

  1. Copy the full SHA
    1a3edaa View commit details

Commits on Sep 21, 2017

  1. Merge pull request #4995 from asterite/feature/macro-resolve-alias

    Macros: automatically resolve alias in types
    asterite authored Sep 21, 2017
    Copy the full SHA
    3ca5428 View commit details
Showing with 10 additions and 0 deletions.
  1. +8 −0 spec/compiler/codegen/macro_spec.cr
  2. +2 −0 src/compiler/crystal/macros/interpreter.cr
8 changes: 8 additions & 0 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -1690,4 +1690,12 @@ describe "Code gen: macro" do
end
), filename: "somedir/bar.cr", inject_primitives: false).to_i.should eq(7)
end

it "resolves alias in macro" do
run(%(
alias Foo = Int32 | String
{{ Foo.union_types.size }}
)).to_i.should eq(2)
end
end
2 changes: 2 additions & 0 deletions src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
@@ -402,6 +402,8 @@ module Crystal
when Const
matched_type.value
when Type
matched_type = matched_type.remove_alias

# If it's the T of a variadic generic type, produce tuple literals
# or named tuple literals. The compiler has them as a type
# (a tuple type, or a named tuple type) but the user should see