Commit 3734a256 by Ian Lance Taylor

compiler: Accept untyped integral values as string/array indices.

    
    When determining the type of an index for a string/array indexing
    expression, the gofrontend would disallow floating-point and complex
    values even if they were integral and throw an internal error.  This
    patch changes gofrontend to use an integral type context when
    determining the types of a string/array index.
    
    Fixes golang/go#11545.
    
    Reviewed-on: https://go-review.googlesource.com/13796

From-SVN: r228270
parent 01bdcc80
66c113f1af300ce27b99f18f792901d7327d6699
f187e13b712824b08f2a8833033840cd52a3b95a
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
......@@ -9870,11 +9870,26 @@ void
Array_index_expression::do_determine_type(const Type_context*)
{
this->array_->determine_type_no_context();
this->start_->determine_type_no_context();
Type_context index_context(Type::lookup_integer_type("int"), false);
if (this->start_->is_constant())
this->start_->determine_type(&index_context);
else
this->start_->determine_type_no_context();
if (this->end_ != NULL)
this->end_->determine_type_no_context();
{
if (this->end_->is_constant())
this->end_->determine_type(&index_context);
else
this->end_->determine_type_no_context();
}
if (this->cap_ != NULL)
this->cap_->determine_type_no_context();
{
if (this->cap_->is_constant())
this->cap_->determine_type(&index_context);
else
this->cap_->determine_type_no_context();
}
}
// Check types of an array index.
......@@ -10415,9 +10430,19 @@ void
String_index_expression::do_determine_type(const Type_context*)
{
this->string_->determine_type_no_context();
this->start_->determine_type_no_context();
Type_context index_context(Type::lookup_integer_type("int"), false);
if (this->start_->is_constant())
this->start_->determine_type(&index_context);
else
this->start_->determine_type_no_context();
if (this->end_ != NULL)
this->end_->determine_type_no_context();
{
if (this->end_->is_constant())
this->end_->determine_type(&index_context);
else
this->end_->determine_type_no_context();
}
}
// Check types of a string index.
......
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