Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate TypeNode#has_attribute? and remove references to "attribute" #9950

Merged
merged 3 commits into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/compiler/parser/parser_doc_spec.cr
Expand Up @@ -14,7 +14,7 @@ describe "Parser doc" do
{"enum def", "enum Foo\nend"},
{"constant assign", "A = 1"},
{"alias", "alias Foo = Bar"},
{"attribute", "@[Some]"},
{"annotation", "@[Some]"},
{"private def", "private def foo\nend"},
].each do |(desc, code)|
it "includes doc for #{desc}" do
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/semantic/annotation_spec.cr
Expand Up @@ -892,7 +892,7 @@ describe "Semantic: annotation" do
"funs can only be annotated with: NoInline, AlwaysInline, Naked, ReturnsTwice, Raises, CallConvention"
end

it "doesn't carry link attribute from lib to fun" do
it "doesn't carry link annotation from lib to fun" do
semantic(%(
@[Link("foo")]
lib LibFoo
Expand Down
7 changes: 4 additions & 3 deletions spec/compiler/semantic/doc_spec.cr
Expand Up @@ -107,7 +107,7 @@ describe "Semantic: doc" do
bar.doc.should eq("Hello")
end

it "stores doc for def with attribute" do
it "stores doc for def with annotation" do
result = semantic %(
class Foo
# Hello
Expand All @@ -122,7 +122,7 @@ describe "Semantic: doc" do
bar.doc.should eq("Hello")
end

it "stores doc for def with attribute" do
it "stores doc for def with annotation" do
result = semantic %(
# Hello
@[AlwaysInline]
Expand Down Expand Up @@ -238,8 +238,9 @@ describe "Semantic: doc" do
end
), wants_doc: true
program = result.program
ann = program.types["Flags"]
foo = program.types["Foo"]
foo.has_attribute?("Flags").should be_true
foo.annotation(ann).should_not be_nil
foo.doc.should eq("Hello")
foo.locations.not_nil!.size.should eq(1)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/compiler/semantic/enum_spec.cr
Expand Up @@ -349,7 +349,8 @@ describe "Semantic: enum" do
SomeFacts::AppleLover
))
enum_type = result.program.types["SomeFacts"].as(EnumType)
enum_type.has_attribute?("Flags").should be_true
annotation_type = result.program.types["Flags"].as(AnnotationType)
enum_type.annotation(annotation_type).should_not be_nil
end

it "can use macro expression inside enum" do
Expand Down
8 changes: 4 additions & 4 deletions spec/compiler/semantic/lib_spec.cr
Expand Up @@ -366,7 +366,7 @@ describe "Semantic: lib" do
"'lib' link argument must be a String"
end

it "clears attributes after lib" do
it "clears annotations after lib" do
assert_type(%(
@[Link("foo")]
lib LibFoo
Expand Down Expand Up @@ -494,7 +494,7 @@ describe "Semantic: lib" do
"can't define method in lib LibC"
end

it "reopens lib and adds more link attributes" do
it "reopens lib and adds more link annotations" do
result = semantic(%(
@[Link("SDL")]
lib LibSDL
Expand All @@ -514,7 +514,7 @@ describe "Semantic: lib" do
attrs[1].lib.should eq("SDLMain")
end

it "reopens lib and adds same link attributes" do
it "reopens lib and adds same link annotations" do
result = semantic(%(
@[Link("SDL")]
lib LibSDL
Expand All @@ -533,7 +533,7 @@ describe "Semantic: lib" do
attrs[0].lib.should eq("SDL")
end

it "gathers link attributes from macro expression" do
it "gathers link annotations from macro expression" do
result = semantic(%(
{% begin %}
@[Link("SDL")]
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/crystal/macros.cr
Expand Up @@ -1581,9 +1581,6 @@ module Crystal::Macros
# class TypeOf < ASTNode
# end

# class Attribute < ASTNode
# end

# A macro expression,
# surrounded by {{ ... }} (output = true)
# or by {% ... %} (output = false)
Expand Down Expand Up @@ -1925,6 +1922,7 @@ module Crystal::Macros
# Returns `true` if this type has an attribute. For example `@[Flags]`
# or `@[Packed]` (the name you pass to this method is `"Flags"` or `"Packed"`
# in these cases).
@[Deprecated("Use #annotation instead")]
def has_attribute?(name : StringLiteral | SymbolLiteral) : BoolLiteral
end

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/macros/interpreter.cr
Expand Up @@ -371,7 +371,7 @@ module Crystal
named_args = node.named_args.try &.to_h { |arg| {arg.name, accept arg.value} }

begin
@last = receiver.interpret(node.name, args, named_args, node.block, self)
@last = receiver.interpret(node.name, args, named_args, node.block, self, node.name_location)
rescue ex : MacroRaiseException
raise ex
rescue ex : Crystal::Exception
Expand Down Expand Up @@ -518,13 +518,13 @@ module Crystal

def visit(node : Splat)
node.exp.accept self
@last = @last.interpret("splat", [] of ASTNode, nil, nil, self)
@last = @last.interpret("splat", [] of ASTNode, nil, nil, self, node.location)
false
end

def visit(node : DoubleSplat)
node.exp.accept self
@last = @last.interpret("double_splat", [] of ASTNode, nil, nil, self)
@last = @last.interpret("double_splat", [] of ASTNode, nil, nil, self, node.location)
false
end

Expand Down