Skip to content

Commit

Permalink
Allow nested constants in type lookup for generic arguments that reso…
Browse files Browse the repository at this point in the history
…lve to integers (#5532)
  • Loading branch information
asterite authored and RX14 committed Jan 4, 2018
1 parent 0ea5ca0 commit d1355e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions spec/compiler/semantic/static_array_spec.cr
Expand Up @@ -60,6 +60,27 @@ describe "Semantic: static array" do
)) { static_array_of(char, 3) }
end

it "types static array new with size being a nested constant inside type declaration (#5426)" do
assert_type(%(
module Moo
SIZE = 3
end
class Foo
@x : StaticArray(Char, Moo::SIZE)
def initialize(@x)
end
def x
@x
end
end
Foo.new(StaticArray(Char, Moo::SIZE).new).x
)) { static_array_of(char, 3) }
end

it "types static array new with size being a computed constant" do
assert_type(%(
OTHER = 10
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_lookup.cr
Expand Up @@ -249,7 +249,7 @@ class Crystal::Type
end

# Check the case of T resolving to a number
if type_var.is_a?(Path) && type_var.names.size == 1
if type_var.is_a?(Path)
type = @root.lookup_path(type_var)
case type
when Const
Expand Down

0 comments on commit d1355e7

Please sign in to comment.