mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge pull request #439 from crystal-ameba/fix-issue-353
Make `Lint/SharedVarInFiber` rule account for `loop { ... }`
This commit is contained in:
commit
c9bc01f88c
4 changed files with 89 additions and 2 deletions
|
@ -39,7 +39,7 @@ module Ameba::Rule::Lint
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is a shared var in spawn" do
|
||||
it "reports if there is a shared var in spawn (while)" do
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
i = 0
|
||||
while i < 10
|
||||
|
@ -56,6 +56,24 @@ module Ameba::Rule::Lint
|
|||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "reports if there is a shared var in spawn (loop)" do
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
i = 0
|
||||
loop do
|
||||
break if i >= 10
|
||||
spawn do
|
||||
puts(i)
|
||||
# ^ error: Shared variable `i` is used in fiber
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
||||
Fiber.yield
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "reports reassigned reference to shared var in spawn" do
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
channel = Channel(String).new
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue