internal/core/export: fix crash with let comprehension export

Change-Id: Ica731afeac75dd7faab30a33d85f81ef7926d8ba
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7903
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/internal/core/export/adt.go b/internal/core/export/adt.go
index 58da232..9cece16 100644
--- a/internal/core/export/adt.go
+++ b/internal/core/export/adt.go
@@ -455,7 +455,10 @@
 			y = x.Dst
 
 		case *adt.LetClause:
-			clause := &ast.LetClause{Expr: e.expr(x.Expr)}
+			clause := &ast.LetClause{
+				Ident: e.ident(x.Label),
+				Expr:  e.expr(x.Expr),
+			}
 			c.Clauses = append(c.Clauses, clause)
 
 			_, saved := e.pushFrame(nil)
diff --git a/internal/core/export/testdata/adt.txtar b/internal/core/export/testdata/adt.txtar
index bac856a..a13f3b7 100644
--- a/internal/core/export/testdata/adt.txtar
+++ b/internal/core/export/testdata/adt.txtar
@@ -77,6 +77,12 @@
         "foo\(i)": v
     }
 
+	x: [
+		for x in src
+		let y = x {
+			y
+		}
+	]
 }
 
 errorStructDef: {
@@ -161,6 +167,9 @@
 	for i, v in src {
 		"foo\(i)": v
 	}
+	x: [ for x in src let y = x {
+		y
+	}]
 }
 errorStructDef: {
 	a:    1
@@ -215,6 +224,10 @@
 [y1 src 0]
 [y1 src 1]
 [y1 src 2]
+[y1 x]
+[y1 x 0]
+[y1 x 1]
+[y1 x 2]
 [y1 foo0]
 [y1 bar1]
 [y1 bar2]
@@ -291,6 +304,7 @@
 		bar1: 2
 		bar2: 3
 		foo1: 2
+		x: [1, 2, 3]
 		foo2: 3
 	}
 	errorStructDef: {