Skip to content

Internal error with cue eval -e #4202

@JensRantil

Description

@JensRantil

What version of CUE are you using (cue version)?

$ cue version
cue version (devel)

CUE language version v0.15.1

Go version go1.25.4
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG containermaxprocs=0,decoratemappings=0,tlssha1=1,updatemaxprocs=0,x509sha256skid=0
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin
         GOARM64 v8.0

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

Two files:

match.json

{
  "pageProps": {
    "__APOLLO_STATE__": {
      "SecondProperty:12345": {
        "agentId": "767"
      }
    }
  },
  "__N_SSP": true
}

schema.cue

#Property: {
    type: string
    type: "FirstProperty" | "SecondProperty"
    
    agentId: string | null
}

pageProps: {
    "__APOLLO_STATE__": {
        [#FirstPropertyKey]: #SoldProperty
        [#SecondPropertyKey]: #SoldProperty
    }
    ...
}

#SoldProperty: {
    objectType: string
    agentId: string | null
    ...
}

#FirstPropertyKeyRegex: "^FirstProperty:.*"
#FirstPropertyKey: string
#FirstPropertyKey: =~ #FirstPropertyKeyRegex

#SecondPropertyKeyRegex: =~"^SecondProperty:.*"
#SecondPropertyKey: string
#SecondPropertyKey: =~ #SecondPropertyKeyRegex

_secondProperties: [#Property] | []
_secondProperties: [
    for k, v in pageProps["__APOLLO_STATE__"]
    if k =~ #SecondPropertyKeyRegex {
        {
            type: "SecondProperty"
            agentId: *v.agentId | null
        }
    }
]

_finalProperty: #Property
_finalProperty: _secondProperties[0]

_clean: #Property & {
    type: _finalProperty.type
    agentId: _finalProperty.agentId
}

I executed cue eval schema.cue match.json -e _clean.

What did you expect to see?

I expected to see the evaluated content of _clean written to standard out. Something like

{
    "type": "SecondProperty",
    "agentId": "767"
}

What did you see instead?

// ""cuelang.org/go/internal/core/export".Vertex: internal error
// Error: reference "FIRSTPROPERTYKEY" in label expression refers to field against which it would be matched (and 1 more errors)
//
// Profile:
// export.Profile{Simplify:true, Final:false, TakeDefaults:true, ShowOptional:false, ShowDefinitions:true, ShowHidden:false, ShowDocs:false, ShowAttributes:false, ShowErrors:false, SelfContained:false, Fragment:false, AddPackage:false, InlineImports:false, ExpandReferences:false}
//
// Value:
// {
//     type:    string & ("FirstProperty" | "SecondProperty") & _finalProperty.type
//     agentId: (string | null) & _finalProperty.agentId
// }
//
// You could file a bug with the above information at:
//     https://cuelang.org/issues/new?assignees=&labels=NeedsInvestigation&template=bug_report.md&title=.
//
_|_

Additional comments

Given that it refers me to submit an issue, I simply assume that this is a bug. I have simplified significantly and hope I have not made any typos. I would not be surprised if this bug(?) could be simplified even further.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions