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

Remove compiler warnings #7652

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions etc/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ _crystal()
;;
build)
if [[ ${cur} == -* ]] ; then
local opts="--cross-compile --debug --emit --error-on-warnings --exclude-warnings --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --single-module --threads --target --verbose --warnings --help"
local opts="--cross-compile --debug --emit --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --single-module --threads --target --verbose --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
;;
run)
if [[ ${cur} == -* ]] ; then
local opts="--debug --define --emit --error-on-warnings --exclude-warnings --format --help --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --stats --single-module --threads --verbose --warnings"
local opts="--debug --define --emit --format --help --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --stats --single-module --threads --verbose"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
Expand Down
229 changes: 0 additions & 229 deletions spec/compiler/codegen/warnings_spec.cr

This file was deleted.

30 changes: 30 additions & 0 deletions spec/compiler/semantic/deprecated_annotation_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "../../spec_helper"

describe "Deprecated" do
it "errors if invalid argument type" do
assert_error %(
@[Deprecated(42)]
def foo
end
),
"Error in line 3: first argument must be a String"
end

it "errors if too many arguments" do
assert_error %(
@[Deprecated("Do not use me", "extra arg")]
def foo
end
),
"Error in line 3: wrong number of deprecated annotation arguments (given 2, expected 1)"
end

it "errors if missing link arguments" do
assert_error %(
@[Deprecated(invalid: "Do not use me")]
def foo
end
),
"Error in line 3: too many named arguments (given 1, expected maximum 0)"
end
end
20 changes: 0 additions & 20 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,6 @@ def assert_error(str, message, inject_primitives = true)
end
end

def warnings_result(code, inject_primitives = true)
code = inject_primitives(code) if inject_primitives

output_filename = Crystal.tempfile("crystal-spec-output")

compiler = Compiler.new
compiler.warnings = Warnings::All
compiler.error_on_warnings = false
compiler.prelude = "empty" # avoid issues in the current std lib
result = compiler.compile Compiler::Source.new("code.cr", code), output_filename

result.program.warning_failures
end

def assert_warning(code, message, inject_primitives = true)
warning_failures = warnings_result(code, inject_primitives)
warning_failures.size.should eq(1)
warning_failures[0].should start_with(message)
end

def assert_macro(macro_args, macro_body, call_args, expected, expected_pragmas = nil, flags = nil)
assert_macro(macro_args, macro_body, expected, expected_pragmas, flags) { call_args }
end
Expand Down
11 changes: 11 additions & 0 deletions src/annotations.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This annotations marks methods, classes, constants, and macros as deprecated.
#
# It receives an optional `StringLiteral` as single argument containing a deprecation notice.
#
# ```
# @[Deprecated("Use `#bar` instead")]
# def foo
# end
# ```
annotation Deprecated
end
2 changes: 0 additions & 2 deletions src/compiler/crystal/codegen/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Crystal::CodeGenVisitor
return false
end

check_call_to_deprecated_method node

owner = node.name == "super" ? node.scope : node.target_def.owner

call_args, has_out = prepare_call_args node, owner
Expand Down
34 changes: 34 additions & 0 deletions src/compiler/crystal/codegen/deprecated.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Crystal
struct DeprecatedAnnotation
getter message : String?

def initialize(@message = nil)
end

def self.from(ann : Annotation)
args = ann.args
named_args = ann.named_args

if named_args
ann.raise "too many named arguments (given #{named_args.size}, expected maximum 0)"
end

message = nil
count = 0

args.each do |arg|
case count
when 0
arg.raise "first argument must be a String" unless arg.is_a?(StringLiteral)
message = arg.value
else
ann.wrong_number_of "deprecated annotation arguments", args.size, "1"
end

count += 1
end

new(message)
end
end
end
Loading