Commit a763aa92 by Ian Lance Taylor

compiler: Don't crash on type switch case nil with selector.

From-SVN: r183782
parent 7d189538
...@@ -3848,6 +3848,24 @@ Variable::add_preinit_statement(Gogo* gogo, Statement* s) ...@@ -3848,6 +3848,24 @@ Variable::add_preinit_statement(Gogo* gogo, Statement* s)
b->set_end_location(s->location()); b->set_end_location(s->location());
} }
// Whether this variable has a type.
bool
Variable::has_type() const
{
if (this->type_ == NULL)
return false;
// A variable created in a type switch case nil does not actually
// have a type yet. It will be changed to use the initializer's
// type in determine_type.
if (this->is_type_switch_var_
&& this->type_->is_nil_constant_as_type())
return false;
return true;
}
// In an assignment which sets a variable to a tuple of EXPR, return // In an assignment which sets a variable to a tuple of EXPR, return
// the type of the first element of the tuple. // the type of the first element of the tuple.
......
...@@ -1154,8 +1154,7 @@ class Variable ...@@ -1154,8 +1154,7 @@ class Variable
// Return whether the type is defined yet. // Return whether the type is defined yet.
bool bool
has_type() const has_type() const;
{ return this->type_ != NULL; }
// Get the initial value. // Get the initial value.
Expression* Expression*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment