Procházet zdrojové kódy

Changed the type of `parameter` in FunctionType ctor from generic `Expression` to `TupleLiteral` to match the grammar (#1272)

pk19604014 před 4 roky
rodič
revize
cdc9428984

+ 1 - 1
common/fuzzing/carbon.proto

@@ -19,7 +19,7 @@ message CallExpression {
 }
 
 message FunctionTypeLiteral {
-  optional Expression parameter = 1;
+  optional TupleLiteralExpression parameter = 3;
   optional Expression return_type = 2;
 }
 

+ 1 - 1
common/fuzzing/proto_to_carbon.cpp

@@ -200,7 +200,7 @@ static auto ExpressionToCarbon(const Fuzzing::Expression& expression,
     case Fuzzing::Expression::kFunctionType: {
       const auto& fun_type = expression.function_type();
       out << "__Fn";
-      ExpressionToCarbon(fun_type.parameter(), out);
+      TupleLiteralExpressionToCarbon(fun_type.parameter(), out);
       out << " -> ";
       ExpressionToCarbon(fun_type.return_type(), out);
       break;

+ 4 - 4
explorer/ast/expression.h

@@ -489,7 +489,7 @@ class CallExpression : public Expression {
 class FunctionTypeLiteral : public Expression {
  public:
   explicit FunctionTypeLiteral(SourceLocation source_loc,
-                               Nonnull<Expression*> parameter,
+                               Nonnull<TupleLiteral*> parameter,
                                Nonnull<Expression*> return_type)
       : Expression(AstNodeKind::FunctionTypeLiteral, source_loc),
         parameter_(parameter),
@@ -499,13 +499,13 @@ class FunctionTypeLiteral : public Expression {
     return InheritsFromFunctionTypeLiteral(node->kind());
   }
 
-  auto parameter() const -> const Expression& { return *parameter_; }
-  auto parameter() -> Expression& { return *parameter_; }
+  auto parameter() const -> const TupleLiteral& { return *parameter_; }
+  auto parameter() -> TupleLiteral& { return *parameter_; }
   auto return_type() const -> const Expression& { return *return_type_; }
   auto return_type() -> Expression& { return *return_type_; }
 
  private:
-  Nonnull<Expression*> parameter_;
+  Nonnull<TupleLiteral*> parameter_;
   Nonnull<Expression*> return_type_;
 };
 

+ 1 - 1
explorer/fuzzing/ast_to_proto.cpp

@@ -97,7 +97,7 @@ static auto ExpressionToProto(const Expression& expression)
       const auto& fun_type = cast<FunctionTypeLiteral>(expression);
       auto* fun_type_proto = expression_proto.mutable_function_type();
       *fun_type_proto->mutable_parameter() =
-          ExpressionToProto(fun_type.parameter());
+          TupleLiteralExpressionToProto(fun_type.parameter());
       *fun_type_proto->mutable_return_type() =
           ExpressionToProto(fun_type.return_type());
       break;

+ 11 - 13
explorer/fuzzing/fuzzer_corpus/bbf51fb6519d507da617e8ad2f7aa820354ca2f4.textproto → explorer/fuzzing/fuzzer_corpus/01e7317e461b70aea94c6cb2922236d87ddb03a5.textproto

@@ -245,20 +245,18 @@ compilation_unit {
             type {
               function_type {
                 parameter {
-                  tuple_literal {
-                    fields {
-                      call {
-                        function {
-                          identifier {
-                            name: "Point"
-                          }
+                  fields {
+                    call {
+                      function {
+                        identifier {
+                          name: "Point"
                         }
-                        argument {
-                          tuple_literal {
-                            fields {
-                              identifier {
-                                name: "T"
-                              }
+                      }
+                      argument {
+                        tuple_literal {
+                          fields {
+                            identifier {
+                              name: "T"
                             }
                           }
                         }

+ 3 - 5
explorer/fuzzing/fuzzer_corpus/d191fc4462a50c502d790d51fd58e68346dc1505.textproto → explorer/fuzzing/fuzzer_corpus/035c3272740456e2748925f3ba854ccacadd029e.textproto

@@ -29,11 +29,9 @@ compilation_unit {
                 expression {
                   function_type {
                     parameter {
-                      tuple_literal {
-                        fields {
-                          identifier {
-                            name: "T"
-                          }
+                      fields {
+                        identifier {
+                          name: "T"
                         }
                       }
                     }

+ 5 - 9
explorer/fuzzing/fuzzer_corpus/4ac057f4d857b6644a3de54266d932940ebf106a.textproto → explorer/fuzzing/fuzzer_corpus/3045a5c32cd76b94b2ef6664be2a640b92cf68fb.textproto

@@ -422,11 +422,9 @@ compilation_unit {
                     expression {
                       function_type {
                         parameter {
-                          tuple_literal {
-                            fields {
-                              identifier {
-                                name: "T"
-                              }
+                          fields {
+                            identifier {
+                              name: "T"
                             }
                           }
                         }
@@ -463,10 +461,8 @@ compilation_unit {
                     expression {
                       function_type {
                         parameter {
-                          tuple_literal {
-                            fields {
-                              int_type_literal {
-                              }
+                          fields {
+                            int_type_literal {
                             }
                           }
                         }

+ 3 - 5
explorer/fuzzing/fuzzer_corpus/09e83bb511e0d695ff3608a746040ae7c69cc984.textproto → explorer/fuzzing/fuzzer_corpus/cc5dd89a2ca0db94774b36ee1a9eb31156e6b6af.textproto

@@ -22,11 +22,9 @@ compilation_unit {
                 expression {
                   function_type {
                     parameter {
-                      tuple_literal {
-                        fields {
-                          identifier {
-                            name: "T"
-                          }
+                      fields {
+                        identifier {
+                          name: "T"
                         }
                       }
                     }

+ 2 - 1
explorer/fuzzing/fuzzer_util_test.cpp

@@ -29,7 +29,8 @@ TEST(FuzzerUtilTest, RunFuzzerOnCorpus) {
     contents << file.rdbuf();
     Fuzzing::Carbon carbon_proto;
     ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(contents.str(),
-                                                              &carbon_proto));
+                                                              &carbon_proto))
+        << " couldn't parse text proto in " << f;
     ParseAndExecute(carbon_proto.compilation_unit());
     ++file_count;
   }