TBR Fix vdltest MimicValue for non-nil any values.

Change-Id: I40dff5d2d76aad8a0f655340abab63ca70ecb837
diff --git a/vdl/vdltest/mimic_value.go b/vdl/vdltest/mimic_value.go
index 5bdf287..e34cee3 100644
--- a/vdl/vdltest/mimic_value.go
+++ b/vdl/vdltest/mimic_value.go
@@ -30,21 +30,37 @@
 func MimicValue(tt *vdl.Type, base *vdl.Value) *vdl.Value {
 	// Handle nil first, to get rid of pesky corner cases.  After this is done,
 	// we've flattened the base value to its non-nil element.
+	baseWasAny := false
 	if base.Kind() == vdl.Any && !base.IsNil() {
+		baseWasAny = true
 		base = base.Elem()
 	}
 	if base.IsNil() {
 		return mimicNilValue(tt, base)
 	}
-	// Now we know we're dealing with a non-nil base.  Flatten tt to a non-any
-	// non-optional type.
+	// Now we know we're dealing with a non-nil non-any base.
 	if tt == vdl.AnyType {
-		// If we're asked to build a value of any type, we must build exactly the
-		// same type as the base.  It's not good enough to build a value of a
-		// compatible type; if the base itself is an any type, it must be populated
-		// with a value of the exact type.
+		// We've been asked to build a value of any type, so we build exactly the
+		// same type as the base.  There are two cases:
+		//   1) base: int64      tt: any
+		//   2) base: any(int64) tt: any
+		//
+		// For case 1 we could actually fill in tt with any type compatible with the
+		// base type, but for case 2 we must fill in tt with the exact base type;
+		// see case 4 below.  For simplicity we just always use the exact base type.
 		tt = base.Type()
 	}
+	if baseWasAny && tt != base.Type() {
+		// If base was an any value, tt must be exactly the same type as the base.
+		// There are two cases:
+		//   3) base: any(int64) tt: int64
+		//   4) base: any(int64) tt: any(int64)
+		//
+		// Note that it's not good enough to mimic a value of a compatible type tt;
+		// if we changed tt to int16 above, we wouldn't end up with a result of the
+		// right type.  Case 4 was ensured by case 2 above.
+		return nil
+	}
 	value := mimicNonNilValue(tt.NonOptional(), base.NonOptional())
 	if value == nil {
 		return nil
diff --git a/vdl/vdltest/vdltest.vdl.go b/vdl/vdltest/vdltest.vdl.go
index e64a122..b25a56f 100644
--- a/vdl/vdltest/vdltest.vdl.go
+++ b/vdl/vdltest/vdltest.vdl.go
@@ -30648,9 +30648,9 @@
 		Target: []interface{}{
 			int64(-123),
 		},
-		SourceLabel: "[]int16{-123}",
-		Source: []int16{
-			-123,
+		SourceLabel: "VList_Any{int64(-123)}",
+		Source: VList_Any{
+			int64(-123),
 		},
 	},
 	{
@@ -60466,11 +60466,11 @@
 			int64(-123),
 			int64(-123),
 		},
-		SourceLabel: "XList_XFloat32{-123, -123, -123}",
-		Source: XList_XFloat32{
-			-123,
-			-123,
-			-123,
+		SourceLabel: "XList_Any{int64(-123), int64(-123), int64(-123)}",
+		Source: XList_Any{
+			int64(-123),
+			int64(-123),
+			int64(-123),
 		},
 	},
 	{
diff --git a/vdl/vdltest/ventry_pass_gen.vdl b/vdl/vdltest/ventry_pass_gen.vdl
index e3e2ce6..bcc554a 100644
--- a/vdl/vdltest/ventry_pass_gen.vdl
+++ b/vdl/vdltest/ventry_pass_gen.vdl
@@ -38,8 +38,8 @@
 // |struct    |163, 180| 0,  0| 0,  0| 0, 0| 0, 0| 57, 57|  0, 0| 47, 44| 59, 79| 59, 80| [!can max=2]
 // |union     |159, 163| 0,  0| 0,  0| 0, 0| 0, 0| 56, 56|  0, 0| 46, 46| 57, 61| 57,  4| [!can max=2]
 // --------------------------------------------------------------------------------------
-// |IsNamed   |668, 901|10, 57|10, 92| 6,22| 6,32|230,204|  0, 0|174,163|232,331|232,239| [!can max=11]
-// |IsUnnamed |279, 595|10, 57|10, 92| 6,22| 6,32| 91,103|  0, 8| 64, 56| 92,225| 92,165| [!can max=11]
+// |IsNamed   |668, 902|10, 57|10, 92| 6,22| 6,32|230,205|  0, 0|174,163|232,331|232,239| [!can max=11]
+// |IsUnnamed |279, 594|10, 57|10, 92| 6,22| 6,32| 91,102|  0, 8| 64, 56| 92,225| 92,165| [!can max=11]
 // |IsBytes   | 18,  15| 0,  0| 0,  0| 0, 0| 0, 0|  6,  4|  0, 0|  6,  2|  6,  9|  6,  3| [!can max=2]
 // --------------------------------------------------------------------------------------
 // 
@@ -1636,7 +1636,7 @@
 	{ false, `Zero`, `[]any{}`, []any{}, `[]string{}`, []string{} },
 	// Canonical
 	{ true, `Full`, `[]any{int64(-123)}`, []any{int64(-123)}, `[]any{int64(-123)}`, []any{int64(-123)} },
-	{ false, `Full`, `[]any{int64(-123)}`, []any{int64(-123)}, `[]int16{-123}`, []int16{-123} },
+	{ false, `Full`, `[]any{int64(-123)}`, []any{int64(-123)}, `VList_Any{int64(-123)}`, VList_Any{int64(-123)} },
 	// Canonical
 	{ true, `Random0`,
 	  `[]any{VSet_VString{"", "abcdeΔΘΠΣ"}}`,
diff --git a/vdl/vdltest/xentry_pass_gen.vdl b/vdl/vdltest/xentry_pass_gen.vdl
index c7b1372..7b3d722 100644
--- a/vdl/vdltest/xentry_pass_gen.vdl
+++ b/vdl/vdltest/xentry_pass_gen.vdl
@@ -686,8 +686,8 @@
 	{ false, `Full`,
 	  `XArray3_Any{int64(-123), int64(-123), int64(-123)}`,
 	  XArray3_Any{int64(-123), int64(-123), int64(-123)},
-	  `XList_XFloat32{-123, -123, -123}`,
-	  XList_XFloat32{-123, -123, -123},
+	  `XList_Any{int64(-123), int64(-123), int64(-123)}`,
+	  XList_Any{int64(-123), int64(-123), int64(-123)},
 	},
 	// Canonical
 	{ true, `Random0`,