Skip to content

Commit

Permalink
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/compiler/type_inference/lib_spec.cr
Original file line number Diff line number Diff line change
@@ -517,6 +517,23 @@ describe "Type inference: lib" do
attrs[0].lib.should eq("SDL")
end

it "gathers link attributes from macro expression" do
result = infer_type(%(
{% begin %}
@[Link("SDL")]
{% end %}
lib LibSDL
fun init = SDL_Init : Int32
end
LibSDL.init
))
sdl = result.program.types["LibSDL"].as(LibType)
attrs = sdl.link_attributes.not_nil!
attrs.size.should eq(1)
attrs[0].lib.should eq("SDL")
end

it "errors if using void as argument (related to #508)" do
assert_error %(
lib LibFoo
2 changes: 2 additions & 0 deletions src/compiler/crystal/semantic/base_type_visitor.cr
Original file line number Diff line number Diff line change
@@ -332,6 +332,8 @@ module Crystal
unless node.expanded
@attributes = nil
end
when MacroExpression, MacroIf, MacroFor
# Don't clear attributes that were generating with macros
else
@attributes = nil
end

0 comments on commit 36ab7e8

Please sign in to comment.