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

Exhaustive case #8424

Merged
merged 29 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
daa7dd4
Compiler: warn when case is not exhaustive
asterite Nov 1, 2019
6923864
Ensure all case are exhaustive
asterite Nov 2, 2019
c7a94c0
Take into account nil literal in exhaustiveness check
asterite Nov 10, 2019
f29b5e8
Handle a couple more non-exhaustive cases
asterite Mar 20, 2020
31be555
Simplify enum comparison in spec
asterite Mar 20, 2020
997e95f
Warn on case without cond and without an else.
asterite Mar 22, 2020
6d52df1
Don't consider enum flags for exhaustiveness check
asterite Mar 22, 2020
1d19187
Better code for exhaustive check, which alows mixins enums and other …
asterite Mar 22, 2020
a1a1abe
Refactor exhaustiveness with targets and patterns
asterite Mar 22, 2020
d5d28c6
Check case exhaustiveness for tuple literal
asterite Mar 22, 2020
286617b
Consider the underscore pattern, and general refactors and changes
asterite Mar 23, 2020
599e073
What about non-tuple pattern in tuple literal case
asterite Mar 23, 2020
8b87334
Show each missing case in a separate line
asterite Mar 23, 2020
e465268
Add another spec for @[Flags] enum
asterite Mar 23, 2020
b0255bd
Only visit needed types in case tuple literal condition
asterite Mar 23, 2020
a4a9e5e
Fix a couple more missing exhaustive cases
asterite Mar 23, 2020
6b0a63e
Some cleanups
asterite Mar 23, 2020
b93200b
Don't warn on cond-less case
asterite Mar 23, 2020
14ae14d
TOOD -> TODO
asterite Mar 23, 2020
37833ab
Remove redundant code
asterite Mar 23, 2020
a601ab7
Add parentheses to make things clearer
asterite Mar 23, 2020
37e9bb3
Merge branch 'exhaustive-case' of github.com:asterite/crystal-1 into …
asterite Mar 23, 2020
fc4db2e
Update samples/llvm/brainfuck.cr
asterite Mar 24, 2020
542dde2
Update src/compiler/crystal/tools/table_print.cr
asterite Mar 24, 2020
e1003a9
Update src/unicode/unicode.cr
asterite Mar 24, 2020
4fe9ad9
Update src/unicode/unicode.cr
asterite Mar 24, 2020
220c8de
Run crystal tool format
asterite Mar 24, 2020
f4208eb
Add specs for YAML::PullParser#skip
asterite Mar 25, 2020
59ee0c7
Add a missing `else`
asterite Mar 25, 2020
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
1 change: 1 addition & 0 deletions samples/brainfuck.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Program
when '.'; print tape.get.chr
when '['; pc = @bracket_map[pc] if tape.get == 0
when ']'; pc = @bracket_map[pc] if tape.get != 0
else # skip
end
pc += 1
end
Expand Down
4 changes: 4 additions & 0 deletions samples/llvm/brainfuck.cr
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class Program
i = matching_close_index
when ']'
abort "Unmatched ']' at position #{i}"
else
# skip
end
i += 1
end
Expand All @@ -181,6 +183,8 @@ class Program
open_count += 1
when ']'
open_count -= 1
else
# go on
end

if open_count == 0
Expand Down
14 changes: 10 additions & 4 deletions samples/mt_gc_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,16 @@ def run(threads_num, fibers_num, loops_num, log)
context.log "Done"
end

enum Mode
Run
Ips
Measure
end

threads_num = 4
fibers_num = 1_000
loops_num = 20
mode = :run
mode : Mode = :run

OptionParser.parse do |parser|
parser.on("-i", "--ips", "Benchmark with ips") { mode = :ips }
Expand All @@ -218,12 +224,12 @@ OptionParser.parse do |parser|
end

case mode
when :run
when .run?
run(threads_num, fibers_num, loops_num, true)
when :ips
when .ips?
Benchmark.ips do |x|
x.report("run") { run(threads_num, fibers_num, loops_num, false) }
end
when :measure
when .measure?
puts Benchmark.measure { run(threads_num, fibers_num, loops_num, false) }
end
4 changes: 2 additions & 2 deletions samples/pretty_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PrettyPrinter
read_object
when .eof?
# We are done
else
raise "Bug: unexpected kind: #{@pull.kind}"
when .end_array?, .end_object?
raise "Bug: shouldn't happen"
end
end

Expand Down
6 changes: 6 additions & 0 deletions samples/sdl/fire.cr
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ while true
speed_down[3] = true
when LibSDL::Key::L
turn_right[3] = true
else
# ignore
end
when LibSDL::KEYUP
case event.key.key_sym.sym
Expand Down Expand Up @@ -421,7 +423,11 @@ while true
speed_down[3] = false
when LibSDL::Key::L
turn_right[3] = false
else
# ignore
end
else
# ignore
end
end

Expand Down
23 changes: 17 additions & 6 deletions samples/sdl/tv.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require "./sdl/sdl"

class ColorMaker
enum State
BlueUp
BlueDown
GreenUp
GreenDown
RedUp
RedDown
end

@state : State

def initialize(@delay : Int32)
@r = 0
@g = 255
Expand All @@ -19,22 +30,22 @@ class ColorMaker

def next_state
case @state
when :green_up
when .green_up?
@g += 1
@state = :red_down if @g == 255
when :red_down
when .red_down?
@r -= 1
@state = :blue_up if @r == 0
when :blue_up
when .blue_up?
@b += 1
@state = :green_down if @b == 255
when :green_down
when .green_down?
@g -= 1
@state = :red_up if @g == 0
when :red_up
when .red_up?
@r += 1
@state = :blue_down if @r == 255
when :blue_down
when .blue_down?
@b -= 1
@state = :green_up if @b == 0
end
Expand Down
Loading