THRIFT-1635 D codegen bug for required non-nullable fields 
Patch: David Nadlinger


git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1353316 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/d/src/thrift/codegen/base.d b/lib/d/src/thrift/codegen/base.d
index 9624012..d697375 100644
--- a/lib/d/src/thrift/codegen/base.d
+++ b/lib/d/src/thrift/codegen/base.d
@@ -782,14 +782,14 @@
     // WORKAROUND: To stop LDC from emitting the manifest constant »meta« below
     // into the writeStruct function body this is inside the string mixin
     // block – the code wouldn't depend on it (this is an LDC bug, and because
-    // of it a new array would be allocate on each method invocation at runtime).
+    // of it a new array would be allocated on each method invocation at runtime).
     foreach (name; StaticFilter!(
       Compose!(isNullable, PApply!(MemberType, T)),
       FieldNames!T
     )) {
        static if (memberReq!(T, name, fieldMetaData) == TReq.REQUIRED) {
-         code ~= `enforce(__traits(getMember, s, name) !is null,
-           new TException("Required field '` ~ name ~ `' is null."));\n`;
+         code ~= "enforce(__traits(getMember, s, `" ~ name ~ "`) !is null,
+           new TException(`Required field '" ~ name ~ "' is null.`));\n";
        }
     }
 
@@ -908,6 +908,40 @@
   p.writeStructEnd();
 }
 
+unittest {
+  // Ensure that the generated code at least compiles for the basic field type
+  // combinations. Functionality checks are covered by the rest of the test
+  // suite.
+
+  struct Test {
+    // Non-nullable.
+    int a1;
+    int a2;
+    int a3;
+    int a4;
+
+    // Nullable.
+    string b1;
+    string b2;
+    string b3;
+    string b4;
+
+    mixin TStructHelpers!([
+      TFieldMeta("a1", 1, TReq.OPT_IN_REQ_OUT),
+      TFieldMeta("a2", 2, TReq.OPTIONAL),
+      TFieldMeta("a3", 3, TReq.REQUIRED),
+      TFieldMeta("a4", 4, TReq.IGNORE),
+      TFieldMeta("b1", 5, TReq.OPT_IN_REQ_OUT),
+      TFieldMeta("b2", 6, TReq.OPTIONAL),
+      TFieldMeta("b3", 7, TReq.REQUIRED),
+      TFieldMeta("b4", 8, TReq.IGNORE),
+    ]);
+  }
+
+  static assert(__traits(compiles, { Test t; t.read(cast(TProtocol)null); }));
+  static assert(__traits(compiles, { Test t; t.write(cast(TProtocol)null); }));
+}
+
 private {
   /*
    * Returns a D code string containing the matching TType value for a passed