[mcs] Implements C# 7.2 readonly structs
[mono.git] / mcs / mcs / cs-parser.jay
index 648effd7f1095c7731e5ed6797a6bd3ceb20dd3e..6e20a8b13f0aeedac01b0a29afcb61722a4b34c1 100644 (file)
@@ -1020,13 +1020,16 @@ struct_declaration
          opt_modifiers
          opt_partial
          STRUCT
-         {
-         }
          type_declaration_name
-         { 
+         {
+               var mods = (Modifiers) $2;
+               if ((mods & Modifiers.READONLY) != 0 && lang_version < LanguageVersion.V_7_2) {
+                       FeatureIsNotAvailable (GetLocation ($4), "readonly structs");
+               }
+
                lexer.ConstraintsParsing = true;
                valid_param_mod = ParameterModifierType.PrimaryConstructor;
-               push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
+               push_current_container (new Struct (current_container, (MemberName) $5, mods, (Attributes) $1), $3);
          }
          opt_primary_parameters
          opt_class_base
@@ -1035,11 +1038,11 @@ struct_declaration
                valid_param_mod = 0;
                lexer.ConstraintsParsing = false;
 
-               if ($8 != null)
-                       current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
+               if ($7 != null)
+                       current_type.PrimaryConstructorParameters = (ParametersCompiled) $7;
 
-               if ($10 != null)
-                       current_container.SetConstraints ((List<Constraints>) $10);
+               if ($9 != null)
+                       current_container.SetConstraints ((List<Constraints>) $9);
 
                if (doc_support)
                        current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
@@ -1061,10 +1064,10 @@ struct_declaration
          }
          opt_semicolon
          {
-               if ($16 == null) {
-                       lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
+               if ($15 == null) {
+                       lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
                } else {
-                       lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
+                       lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
                }
                $$ = pop_current_class ();
          }