mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fix type errors in function calls (#308)
* Make `field_list` always a list. * Create separate `paren_expression` and `tuple` nonterminals * Rename expression_or_field_list.* to field_list.* Co-authored-by: Jeremy G. Siek <jsiek@indiana.edu>
This commit is contained in:
committed by
GitHub
co-authored by
Jeremy G. Siek
parent
bf6bb800c4
commit
8b3bb7c5e9
@@ -15,7 +15,7 @@
|
||||
|
||||
%code requires {
|
||||
#include "executable_semantics/ast/declaration.h"
|
||||
#include "executable_semantics/ast/expression_or_field_list.h"
|
||||
#include "executable_semantics/ast/field_list.h"
|
||||
#include "executable_semantics/ast/function_definition.h"
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void yyerror(char* error) {
|
||||
std::list<Carbon::Declaration>* declaration_list;
|
||||
Carbon::Member* member;
|
||||
std::list<Carbon::Member*>* member_list;
|
||||
Carbon::ExpOrFieldList* field_list;
|
||||
Carbon::FieldList* field_list;
|
||||
std::pair<std::string, Carbon::Expression*>* alternative;
|
||||
std::list<std::pair<std::string, Carbon::Expression*>>* alternative_list;
|
||||
std::pair<Carbon::Expression*, Carbon::Statement*>* clause;
|
||||
@@ -62,6 +62,7 @@ void yyerror(char* error) {
|
||||
%type <expression> expression
|
||||
%type <expression> pattern
|
||||
%type <expression> return_type
|
||||
%type <expression> paren_expression
|
||||
%type <expression> tuple
|
||||
%type <member> member
|
||||
%type <member_list> member_list
|
||||
@@ -137,7 +138,7 @@ expression:
|
||||
{ $$ = Carbon::MakeTypeType(yylineno); }
|
||||
| AUTO
|
||||
{ $$ = Carbon::MakeAutoType(yylineno); }
|
||||
| tuple { $$ = $1; }
|
||||
| paren_expression { $$ = $1; }
|
||||
| expression EQUAL expression
|
||||
{ $$ = Carbon::MakeBinOp(yylineno, Carbon::Operator::Eq, $1, $3); }
|
||||
| expression '+' expression
|
||||
@@ -153,38 +154,39 @@ expression:
|
||||
| '-' expression
|
||||
{ $$ = Carbon::MakeUnOp(yylineno, Carbon::Operator::Neg, $2); }
|
||||
| expression tuple
|
||||
{
|
||||
if ($2->tag == Carbon::ExpressionKind::Tuple) {
|
||||
$$ = Carbon::MakeCall(yylineno, $1, $2);
|
||||
} else {
|
||||
auto vec =
|
||||
new std::vector<std::pair<std::string, Carbon::Expression*>>();
|
||||
vec->push_back(std::make_pair("", $2));
|
||||
$$ = Carbon::MakeCall(yylineno, $1, Carbon::MakeTuple(yylineno, vec));
|
||||
}
|
||||
}
|
||||
{ $$ = Carbon::MakeCall(yylineno, $1, $2); }
|
||||
| FNTY tuple return_type
|
||||
{ $$ = Carbon::MakeFunType(yylineno, $2, $3); }
|
||||
;
|
||||
designator: '.' identifier { $$ = $2; }
|
||||
;
|
||||
tuple: '(' field_list ')'
|
||||
paren_expression: '(' field_list ')'
|
||||
{
|
||||
switch ($2->tag) {
|
||||
case Carbon::ExpOrFieldListKind::Exp:
|
||||
$$ = $2->u.exp;
|
||||
break;
|
||||
case Carbon::ExpOrFieldListKind::FieldList:
|
||||
if ($2->fields->size() == 1 &&
|
||||
$2->fields->front().first == "" &&
|
||||
!$2->has_explicit_comma) {
|
||||
$$ = $2->fields->front().second;
|
||||
} else {
|
||||
auto vec = new std::vector<std::pair<std::string,Carbon::Expression*>>(
|
||||
$2->u.fields->begin(), $2->u.fields->end());
|
||||
$2->fields->begin(), $2->fields->end());
|
||||
$$ = Carbon::MakeTuple(yylineno, vec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
;
|
||||
tuple: '(' field_list ')'
|
||||
{
|
||||
auto vec = new std::vector<std::pair<std::string,Carbon::Expression*>>(
|
||||
$2->fields->begin(), $2->fields->end());
|
||||
$$ = Carbon::MakeTuple(yylineno, vec);
|
||||
}
|
||||
field:
|
||||
pattern
|
||||
{ $$ = Carbon::MakeExp($1); }
|
||||
{
|
||||
auto fields =
|
||||
new std::list<std::pair<std::string, Carbon::Expression*>>();
|
||||
fields->push_back(std::make_pair("", $1));
|
||||
$$ = Carbon::MakeFieldList(fields);
|
||||
}
|
||||
| designator '=' pattern
|
||||
{
|
||||
auto fields =
|
||||
|
||||
Reference in New Issue
Block a user