Skip to content

Commit

Permalink
Merge pull request #671 from soutaro/add-level-method
Browse files Browse the repository at this point in the history
Add missing `#level` method
  • Loading branch information
soutaro committed Nov 22, 2022
2 parents c487c56 + ee82a9d commit 3f4983a
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 24 deletions.
7 changes: 4 additions & 3 deletions lib/steep/ast/types/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Types
module Helper
module ChildrenLevel
def level_of_children(children)
children.map(&:level).sort {|a, b| b.size <=> a.size }.inject() do |a, b|
a.zip(b).map do |(x, y)|
levels = children.map(&:level)
children.map(&:level).sort {|a, b| (b.size <=> a.size) || 0 }.inject() do |a, b|
a.zip(b).map do |x, y|
if x && y
x + y
else
x || y
x || y || raise
end
end
end || []
Expand Down
4 changes: 4 additions & 0 deletions lib/steep/ast/types/logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def ==(other)
def to_s
"<% #{self.class} %>"
end

def level
[0]
end
end

class Not < Base
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/any.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[1]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/boolean.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped

Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/bot.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[2]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/class.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped

Expand Down
9 changes: 6 additions & 3 deletions sig/steep/ast/types/helper.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module Steep
module Types
module Helper
module ChildrenLevel
def level_of_children: (untyped children) -> untyped
def level_of_children: (Array[t] children) -> Array[Integer]
end

module NoFreeVariables
def free_variables: () -> untyped
@fvs: Set[Symbol]

def free_variables: () -> Set[Symbol]
end

module NoChild
def each_child: () ?{ () -> untyped } -> (untyped | nil)
def each_child: () { (t) -> void } -> void
| () -> Enumerator[t, void]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/instance.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

def to_s: () -> "instance"

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped

Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/intersection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Steep

def each_child: () ?{ () -> untyped } -> untyped

def level: () -> untyped
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped
end
Expand Down
2 changes: 2 additions & 0 deletions sig/steep/ast/types/logic.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Steep
alias eql? ==

def to_s: () -> ::String

def level: () -> Array[Integer]
end

# A type for `!` (not) operator results.
Expand Down
4 changes: 2 additions & 2 deletions sig/steep/ast/types/name.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Steep

def subst: (Steep::Interface::Substitution s) -> self

def level: () -> ::Array[0]
def level: () -> Array[Integer]
end

class Applying < Base
Expand All @@ -40,7 +40,7 @@ module Steep

include Helper::ChildrenLevel

def level: () -> untyped
def level: () -> Array[Integer]
end

class Singleton < Base
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/nil.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped

Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/record.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Steep
def each_child: () { (t) -> void } -> void
| () -> Enumerator[t, void]

def level: () -> Integer
def level: () -> Array[Integer]

def with_location: (loc new_location) -> self
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/self.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

def free_variables: () -> untyped

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped

Expand Down
4 changes: 2 additions & 2 deletions sig/steep/ast/types/top.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[2]

def level: () -> Array[Integer]
def with_location: (untyped new_location) -> untyped
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/tuple.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Steep
def each_child: () { (t) -> void } -> void
| () -> Enumerator[t, void]

def level: () -> untyped
def level: () -> Array[Integer]

def with_location: (RBS::Location[untyped, untyped] new_location) -> Tuple
end
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/union.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Steep

include Helper::ChildrenLevel

def level: () -> Integer
def level: () -> Array[Integer]

def with_location: (loc new_location) -> Union
end
Expand Down
4 changes: 2 additions & 2 deletions sig/steep/ast/types/var.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[0]

def level: () -> Array[Integer]
def update: (?name: untyped, ?location: untyped) -> untyped

def with_location: (untyped new_location) -> untyped
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/ast/types/void.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Steep

include Helper::NoChild

def level: () -> ::Array[0]
def level: () -> Array[Integer]

def with_location: (untyped new_location) -> untyped
end
Expand Down

0 comments on commit 3f4983a

Please sign in to comment.