Repository: goadesign/goa (go)

Issue:
Non Required attributes with Default/Enum creating error
```
package design

var Storedload = ResultType("application/vnd.test", func() {
	TypeName("Storedload")

	Attributes(func() {
		Attribute("uploaded", Boolean, func() {
			Default(true)
		})
		//Required("uploaded")
	})

	View("default", func() {
		Attribute("uploaded")
	})

})
```
If I comment Required with Default value then it's creating below code. That has a type mismatch error.
```
{
		var zero bool
		if vres.Uploaded == zero {
			vres.Uploaded = true
		}
	}
```

Pull request description:
handle transform on pointer field with default
Fix #2707

Patch:
diff --git a/codegen/go_transform.go b/codegen/go_transform.go
index a033158f..0e8aeda7 100644
--- a/codegen/go_transform.go
+++ b/codegen/go_transform.go
@@ -236,7 +236,7 @@ func transformObject(source, target *expr.AttributeExpr, sourceVar, targetVar st
 		// Default value handling. We need to handle default values if the target
 		// type uses default values (i.e. attributes with default values are
 		// non-pointers) and has a default value set.
-		if tdef := tgtMatt.GetDefault(n); tdef != nil && ta.TargetCtx.UseDefault && !srcMatt.IsRequired(n) {
+		if tdef := tgtMatt.GetDefault(n); tdef != nil && ta.TargetCtx.UseDefault && !ta.TargetCtx.Pointer && !srcMatt.IsRequired(n) {
 			switch {
 			case ta.SourceCtx.IsPrimitivePointer(n, srcMatt.AttributeExpr) || !expr.IsPrimitive(srcc.Type):
 				// source attribute is a primitive pointer or not a primitive


Test patch:
diff --git a/codegen/go_transform_test.go b/codegen/go_transform_test.go
index 1461212a..f1137fec 100644
--- a/codegen/go_transform_test.go
+++ b/codegen/go_transform_test.go
@@ -50,9 +50,10 @@ func TestGoTransform(t *testing.T) {
 		stringT = expr.String
 
 		// attribute contexts used in test cases
-		defaultCtx    = NewAttributeContext(false, false, true, "", scope)
-		defaultCtxPkg = NewAttributeContext(false, false, true, "mypkg", scope)
-		pointerCtx    = NewAttributeContext(true, false, false, "", scope)
+		defaultCtx        = NewAttributeContext(false, false, true, "", scope)
+		defaultCtxPkg     = NewAttributeContext(false, false, true, "mypkg", scope)
+		pointerCtx        = NewAttributeContext(true, false, false, "", scope)
+		defaultPointerCtx = NewAttributeContext(true, false, true, "", scope)
 	)
 	tc := map[string][]struct {
 		Name      string
@@ -169,6 +170,11 @@ func TestGoTransform(t *testing.T) {
 			{"recursive-to-recursive", recursive, recursive, defaultCtx, pointerCtx, srcUseDefaultTgtAllPtrsRecursiveToRecursiveCode},
 			{"composite-to-custom-field", composite, customField, defaultCtx, pointerCtx, srcUseDefaultTgtAllPtrsCompositeToCustomFieldCode},
 		},
+
+		// target type uses default and pointers for all fields
+		"target-type-uses-default-all-ptrs": {
+			{"simple-to-simple", simple, simple, defaultCtx, defaultPointerCtx, srcUseDefaultTgtAllPtrsSimpleToSimpleCode},
+		},
 	}
 	for name, cases := range tc {
 		t.Run(name, func(t *testing.T) {