github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/comprehensions/fields.txtar (about)

     1  Issue #560
     2  
     3  -- cue.mod/module.cue --
     4  module: "example.com"
     5  -- in.cue --
     6  import "strings"
     7  
     8  dynamic: {
     9  	for _, s in ["foo"] {
    10  		(s):       1
    11  		"\(s)bar": 2
    12  	}
    13  }
    14  
    15  issue560: {
    16  	#User: {
    17  		tags_str: string
    18  		tags_map: {
    19  			for k, v in strings.Split(tags_str, " ") {
    20  				"\(v)": string
    21  			}
    22  			"{a}": string
    23  		}
    24  	}
    25  
    26  	user: {
    27  		#User
    28  		tags_str: "b {c}"
    29  	}
    30  }
    31  -- out/eval --
    32  (struct){
    33    dynamic: (struct){
    34      foo: (int){ 1 }
    35      foobar: (int){ 2 }
    36    }
    37    issue560: (struct){
    38      #User: (#struct){
    39        tags_str: (string){ string }
    40        tags_map: (_|_){
    41          // [incomplete] error in call to strings.Split: non-concrete value string:
    42          //     ./in.cue:14:16
    43          //     ./in.cue:12:13
    44          "{a}": (string){ string }
    45        }
    46      }
    47      user: (#struct){
    48        tags_str: (string){ "b {c}" }
    49        tags_map: (#struct){
    50          "{a}": (string){ string }
    51          b: (string){ string }
    52          "{c}": (string){ string }
    53        }
    54      }
    55    }
    56  }
    57  -- out/compile --
    58  --- in.cue
    59  {
    60    dynamic: {
    61      for _, s in [
    62        "foo",
    63      ] {
    64        〈1;s〉: 1
    65        "\(〈1;s〉)bar": 2
    66      }
    67    }
    68    issue560: {
    69      #User: {
    70        tags_str: string
    71        tags_map: {
    72          for k, v in 〈import;strings〉.Split(〈1;tags_str〉, " ") {
    73            "\(〈1;v〉)": string
    74          }
    75          "{a}": string
    76        }
    77      }
    78      user: {
    79        〈1;#User〉
    80        tags_str: "b {c}"
    81      }
    82    }
    83  }