Skip to content

Commit

Permalink
Lint: Remove useless assignments (#12648)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored Oct 31, 2022
1 parent 36bd91e commit 9ae8024
Show file tree
Hide file tree
Showing 52 changed files with 69 additions and 114 deletions.
1 change: 0 additions & 1 deletion samples/binary-trees.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)

puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil

long_lived_tree = bottom_up_tree(0, max_depth)

Expand Down
2 changes: 1 addition & 1 deletion samples/mt_gc_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Context
@threads_state.set(State::Wait)

# spin wait for threads to finish the round
while (c = @threads_reached.get) < @threads
while @threads_reached.get < @threads
end
log "All threads_reached!"
end
Expand Down
4 changes: 2 additions & 2 deletions samples/red_black_tree.cr
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ class RedBlackTreeRunner
@n = n

random = Random.new(1234) # repeatable random seq
@a1 = Array(Int32).new(n) { rand(99_999) }
@a1 = Array(Int32).new(n) { random.rand(99_999) }

random = Random.new(4321) # repeatable random seq
@a2 = Array(Int32).new(n) { rand(99_999) }
@a2 = Array(Int32).new(n) { random.rand(99_999) }

@tree = RedBlackTree.new
end
Expand Down
2 changes: 1 addition & 1 deletion samples/wordcount.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ end

in_filenames = ARGV

do_work ARGV, output_filename, ignore_case
do_work in_filenames, output_filename, ignore_case
16 changes: 8 additions & 8 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3100,27 +3100,27 @@ module Crystal
it "returns true if file exists" do
run(%q<
{{file_exists?("#{__DIR__}/../data/build")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(10)
>, filename: __FILE__).to_i.should eq(10)
end

it "returns false if file doesn't exist" do
run(%q<
{{file_exists?("#{__DIR__}/../data/build_foo")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(20)
>, filename: __FILE__).to_i.should eq(20)
end
end

context "with relative path" do
it "reads file (exists)" do
run(%q<
{{file_exists?("spec/compiler/data/build")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(10)
>, filename: __FILE__).to_i.should eq(10)
end

it "reads file (doesn't exist)" do
run(%q<
{{file_exists?("spec/compiler/data/build_foo")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(20)
>, filename: __FILE__).to_i.should eq(20)
end
end
end
Expand All @@ -3130,7 +3130,7 @@ module Crystal
it "reads file (exists)" do
run(%q<
{{read_file("#{__DIR__}/../data/build")}}
>, filename = __FILE__).to_string.should eq(File.read("#{__DIR__}/../data/build"))
>, filename: __FILE__).to_string.should eq(File.read("#{__DIR__}/../data/build"))
end

it "reads file (doesn't exist)" do
Expand All @@ -3145,7 +3145,7 @@ module Crystal
it "reads file (exists)" do
run(%q<
{{read_file("spec/compiler/data/build")}}
>, filename = __FILE__).to_string.should eq(File.read("spec/compiler/data/build"))
>, filename: __FILE__).to_string.should eq(File.read("spec/compiler/data/build"))
end

it "reads file (doesn't exist)" do
Expand All @@ -3162,15 +3162,15 @@ module Crystal
it "reads file (doesn't exist)" do
run(%q<
{{read_file?("#{__DIR__}/../data/build_foo")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(20)
>, filename: __FILE__).to_i.should eq(20)
end
end

context "with relative path" do
it "reads file (doesn't exist)" do
run(%q<
{{read_file?("spec/compiler/data/build_foo")}} ? 10 : 20
>, filename = __FILE__).to_i.should eq(20)
>, filename: __FILE__).to_i.should eq(20)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/parser/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../support/syntax"
private def assert_parser_warning(source, message, *, file = __FILE__, line = __LINE__)
parser = Parser.new(source)
parser.filename = "/foo/bar/baz.cr"
node = parser.parse
parser.parse

warnings = parser.warnings.infos
warnings.size.should eq(1), file: file, line: line
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/semantic/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe "Semantic: class" do
end

it "types generic of generic type" do
result = assert_type("
assert_type("
class Foo(T)
def set
@coco = 2
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@ describe "Semantic: instance var" do
end

it "declares instance var of generic class" do
result = assert_type("
assert_type("
class Foo(T)
@x : T
Expand All @@ -4385,7 +4385,7 @@ describe "Semantic: instance var" do
end

it "declares instance var of generic class after reopen" do
result = assert_type("
assert_type("
class Foo(T)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/virtual_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ describe "Semantic: virtual" do
end

it "uses virtual type as generic type if class is abstract" do
result = assert_type("
assert_type("
abstract class Foo
end
Expand All @@ -619,7 +619,7 @@ describe "Semantic: virtual" do
end

it "uses virtual type as generic type if class is abstract even in union" do
result = assert_type("
assert_type("
abstract class Foo
end
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe "Semantic: warnings" do
compiler.warnings.level = :all
compiler.warnings.exclude_lib_path = true
compiler.prelude = "empty"
result = compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename
compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename

compiler.warnings.infos.size.should eq(1)
end
Expand Down Expand Up @@ -399,7 +399,7 @@ describe "Semantic: warnings" do
compiler.warnings.level = :all
compiler.warnings.exclude_lib_path = true
compiler.prelude = "empty"
result = compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename
compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename

compiler.warnings.infos.size.should eq(1)
end
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ end
def assert_normalize(from, to, flags = nil, *, file = __FILE__, line = __LINE__)
program = new_program
program.flags.concat(flags.split) if flags
normalizer = Normalizer.new(program)
from_nodes = Parser.parse(from)
to_nodes = program.normalize(from_nodes)
to_nodes.to_s.strip.should eq(to.strip), file: file, line: line
Expand Down
2 changes: 1 addition & 1 deletion spec/std/deque_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ describe "Deque" do
a = Deque{1, 2, 3}
count = 0
it = a.each_index
a.each_index.each do
it.each do
count += 1
a.clear
end
Expand Down
4 changes: 2 additions & 2 deletions spec/std/hash_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ describe "Hash" do
it { {"a" => 2, "b" => 3}.reject(["b", "a"]).should eq({} of String => Int32) }
it "does not change current hash" do
h = {"a" => 3, "b" => 6, "c" => 9}
h2 = h.reject("b", "c")
h.reject("b", "c")
h.should eq({"a" => 3, "b" => 6, "c" => 9})
end
end
Expand All @@ -1282,7 +1282,7 @@ describe "Hash" do
it { {"a" => 2, "b" => 3}.select(Set{"b", "a"}).should eq({"a" => 2, "b" => 3}) }
it "does not change current hash" do
h = {"a" => 3, "b" => 6, "c" => 9}
h2 = h.select("b", "c")
h.select("b", "c")
h.should eq({"a" => 3, "b" => 6, "c" => 9})
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ module HTTP

it "will not retry when closed (non-block) (#12464)" do
requests = 0
server_channel = Channel(Nil).new

client = HTTP::Client.new("127.0.0.1", 0)
client.before_request do
Expand All @@ -256,7 +255,6 @@ module HTTP

it "will not retry when closed (block) (#12464)" do
requests = 0
server_channel = Channel(Nil).new

client = HTTP::Client.new("127.0.0.1", 0)
client.before_request do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/headers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe HTTP::Headers do

it "raises an error if header value contains invalid character" do
expect_raises ArgumentError do
headers = HTTP::Headers{"invalid-header" => "\r\nLocation: http://example.com"}
HTTP::Headers{"invalid-header" => "\r\nLocation: http://example.com"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/std/log/context_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe Log do
Log.context.set a: 1
done = Channel(Nil).new

f = spawn do
spawn do
Log.context.metadata.should eq(Log::Metadata.new)
Log.context.set b: 2
Log.context.metadata.should eq(m({b: 2}))
Expand Down
10 changes: 5 additions & 5 deletions spec/std/log/dispatch_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = DirectDispatcher
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.entries.size.should eq(1)
end
end
Expand All @@ -24,7 +24,7 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = SyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.entries.size.should eq(1)
end
end
Expand All @@ -33,22 +33,22 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
retry { backend.entries.size.should eq(1) }
end

it "wait for entries to flush before closing" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.close
backend.entries.size.should eq(1)
end

it "can be closed twice" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.close
backend.close
backend.entries.size.should eq(1)
Expand Down
4 changes: 2 additions & 2 deletions spec/std/oauth2/session_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module OAuth2
typeof(begin
client = Client.new "localhost", "client_id", "client_secret", redirect_uri: "uri", authorize_uri: "/baz"
token = OAuth2::AccessToken::Bearer.new("token", 3600)
session = Session.new(client, token) { |s| }
session = Session.new(client, token, Time.utc) { |s| }
session = Session.new(client, token) { |_| }
session = Session.new(client, token, Time.utc) { |_| }
session.authenticate(HTTP::Client.new("localhost"))
end)
end
2 changes: 0 additions & 2 deletions spec/std/proc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ describe "Proc" do
end

it "does to_s" do
str = IO::Memory.new
f = ->(x : Int32) { x.to_f }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
end

it "does to_s when closured" do
str = IO::Memory.new
a = 1.5
f = ->(x : Int32) { x + a }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
Expand Down
2 changes: 1 addition & 1 deletion spec/std/socket/tcp_socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe TCPSocket, tags: "network" do

TCPServer.open("localhost", port) do |server|
TCPSocket.open("localhost", port) do |client|
sock = server.accept
server.accept
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ describe "String" do
end

it "subs char with string" do
replaced = "foobar".sub do |char|
"foobar".sub do |char|
char.should eq 'f'
"some"
end.should eq("someoobar")
Expand Down
1 change: 0 additions & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,6 @@ module Crystal
end

# First accept all yield expressions and assign them to block vars
i = 0
unless node.exps.empty?
exp_values = Array({LLVM::Value, Type}).new(node.exps.size)

Expand Down
3 changes: 0 additions & 3 deletions src/compiler/crystal/codegen/fun.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Crystal::CodeGenVisitor
func.varargs?
)

p2 = new_fun.params.to_a

func.params.to_a.each_with_index do |p1, index|
attrs = new_fun.attributes(index + 1)
new_fun.add_attribute(attrs, index + 1) unless attrs.value == 0
Expand Down Expand Up @@ -125,7 +123,6 @@ class Crystal::CodeGenVisitor

if @debug.variables? && !target_def.naked?
in_alloca_block do
args_offset = !is_fun_literal && self_type.passed_as_self? ? 2 : 1
location = target_def.location
context.vars.each do |name, var|
next if var.debug_variable_created
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/primitives.cr
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class Crystal::CodeGenVisitor

old_debug_location = @current_debug_location
if @debug.line_numbers? && (location = node.location)
set_current_debug_location(node.location)
set_current_debug_location(location)
end

if type.element_type.has_inner_pointers?
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Crystal::Command

output_filename = Crystal.temp_executable(config.output_filename)

result = config.compile output_filename
config.compile output_filename

unless config.compiler.no_codegen?
report_warnings
Expand Down
Loading

0 comments on commit 9ae8024

Please sign in to comment.