From a763aa92e52338e6ffb7e5b13fc30d49b5a89e93 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 1 Feb 2012 00:02:58 +0000 Subject: compiler: Don't crash on type switch case nil with selector. From-SVN: r183782 --- gcc/go/gofrontend/gogo.cc | 18 ++++++++++++++++++ gcc/go/gofrontend/gogo.h | 3 +-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index e94090b..c65e47f 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -3848,6 +3848,24 @@ Variable::add_preinit_statement(Gogo* gogo, Statement* s) 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 // the type of the first element of the tuple. diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index 7d77c9f..2231e5d 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -1154,8 +1154,7 @@ class Variable // Return whether the type is defined yet. bool - has_type() const - { return this->type_ != NULL; } + has_type() const; // Get the initial value. Expression* -- cgit v1.1