Permalink
Browse files

Don't require compatible types for an if statement unless the stateme…

…nt is an expression.
  • Loading branch information...
ribrdb committed Jan 27, 2011
1 parent 2346c9e commit 7fa9c6294695a391dccdd3364f01c5c2213959bf
@@ -275,7 +275,7 @@ def parse(*args)

def infer_asts(asts)
typer = Mirah::Typer::JVM.new(@transformer)
asts.each {|ast| typer.infer(ast) }
asts.each {|ast| typer.infer(ast, true) }
begin
typer.resolve(false)
ensure
@@ -282,7 +282,7 @@ def initialize(parent, error)
@resolved = true
end

def infer(typer)
def infer(typer, expression)
end
end

@@ -368,7 +368,7 @@ def initialize(parent, position, name)
super(parent, position, [])
end

def infer(typer)
def infer(typer, expression)
@inferred_type ||= begin
# TODO lookup constant, inline if we're supposed to.
typer.type_reference(scope, name, @array, true)
@@ -382,7 +382,7 @@ def type_reference(typer)

class Self < Node
include Scoped
def infer(typer)
def infer(typer, expression)
@inferred_type ||= scope.static_scope.self_type
end
end
@@ -422,7 +422,7 @@ def [](name)
@values[name]
end

def infer(typer)
def infer(typer, expression)
@inferred ||= begin
@name = name_node.type_reference(typer).name if name_node
@values.each do |name, value|
@@ -57,14 +57,14 @@ def validate_parameters
end
end

def infer(typer)
def infer(typer, expression)
unless @inferred_type
@self_type ||= scope.static_scope.self_type
receiver_type = @self_type
should_defer = false

parameter_types = parameters.map do |param|
typer.infer(param) || should_defer = true
typer.infer(param, true) || should_defer = true
end

parameter_types << Mirah::AST.block_type if block
@@ -78,14 +78,14 @@ def infer(typer)
elsif parameters.size == 0 && scope.static_scope.include?(name)
@inlined = Local.new(parent, position, name)
proxy.__inline__(@inlined)
return proxy.infer(typer)
return proxy.infer(typer, expression)
else
@inferred_type = typer.method_type(receiver_type, name,
parameter_types)
if @inferred_type.kind_of? InlineCode
@inlined = @inferred_type.inline(typer.transformer, self)
proxy.__inline__(@inlined)
return proxy.infer(typer)
return proxy.infer(typer, expression)
end
end
end
@@ -158,12 +158,12 @@ def arguments
args
end

def infer(typer)
def infer(typer, expression)
unless @inferred_type
receiver_type = typer.infer(target)
receiver_type = typer.infer(target, true)
should_defer = receiver_type.nil?
parameter_types = parameters.map do |param|
typer.infer(param) || should_defer = true
typer.infer(param, true) || should_defer = true
end

parameter_types << Mirah::AST.block_type if block
@@ -174,7 +174,7 @@ def infer(typer)
if @inferred_type.kind_of? InlineCode
@inlined = @inferred_type.inline(typer.transformer, self)
proxy.__inline__(@inlined)
return proxy.infer(typer)
return proxy.infer(typer, expression)
end
end

@@ -257,14 +257,14 @@ def name
call_parent.name
end

def infer(typer)
def infer(typer, expression)
@self_type ||= scope.static_scope.self_type.superclass

unless @inferred_type
receiver_type = call_parent.defining_class.superclass
should_defer = receiver_type.nil?
parameter_types = parameters.map do |param|
typer.infer(param) || should_defer = true
typer.infer(param, true) || should_defer = true
end

unless should_defer
@@ -105,14 +105,14 @@ def declare_field(position, name, type)
append_node(field)
end

def infer(typer)
def infer(typer, expression)
resolve_if(typer) do
@superclass = superclass_node.type_reference(typer) if superclass_node
@annotations.each {|a| a.infer(typer)} if @annotations
@annotations.each {|a| a.infer(typer, true)} if @annotations
@interfaces.concat(@interface_nodes.map{|n| n.type_reference(typer)})
typer.define_type(self, name, superclass, @interfaces) do
static_scope.self_type = typer.self_type
typer.infer(body) if body
typer.infer(body, false) if body
end
end
end
@@ -154,7 +154,7 @@ def initialize(parent, position, name, annotations)
@children = yield(self)
end

def infer(typer)
def infer(typer, expression)
resolve_if(typer) do
@interfaces = interface_nodes.map {|i| i.type_reference(typer)}
super
@@ -216,9 +216,9 @@ def initialize(parent, position, name, annotations=[], static = false, &block)
@static = static
end

def infer(typer)
def infer(typer, expression)
resolve_if(typer) do
@annotations.each {|a| a.infer(typer)} if @annotations
@annotations.each {|a| a.infer(typer, true)} if @annotations
@type = type_node.type_reference(typer)
end
end
@@ -249,13 +249,13 @@ def initialize(parent, position, name, annotations=[], static = false, &block)
@static = static
end

def infer(typer)
def infer(typer, expression)
resolve_if(typer) do
@annotations.each {|a| a.infer(typer)} if @annotations
@annotations.each {|a| a.infer(typer, true)} if @annotations
if static
typer.learn_static_field_type(class_scope, name, typer.infer(value))
typer.learn_static_field_type(class_scope, name, typer.infer(value, true))
else
typer.learn_field_type(class_scope, name, typer.infer(value))
typer.learn_field_type(class_scope, name, typer.infer(value, true))
end
end
end
@@ -275,9 +275,9 @@ def initialize(parent, position, name, annotations=[], static = false, &block)
@static = static
end

def infer(typer)
def infer(typer, expression)
resolve_if(typer) do
@annotations.each {|a| a.infer(typer)} if @annotations
@annotations.each {|a| a.infer(typer, true)} if @annotations
if static
typer.static_field_type(class_scope, name)
else
@@ -297,15 +297,15 @@ def initialize(parent, line_number, name)
class_scope.current_access_level = name.to_sym
end

def infer(typer)
def infer(typer, expression)
typer.no_type
end
end

class Include < Node
include Scoped

def infer(typer)
def infer(typer, expression)
children.each do |type|
typeref = type.type_reference(typer)
the_scope = scope.static_scope
Oops, something went wrong.

0 comments on commit 7fa9c62

Please sign in to comment.