this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/export: avoid panic on non-regular identifiers for packages

The logic assumed that package identifiers are all regular
strings, but that's not necessarily the case.
The specification does explicitly disallow definition identifiers
for package names, but does not disallow "private"
identifiers.

We should probably make a subsequent change to error
when the identifier is a definition, but as that might
have more wide-ranging effects, we'll do that in
another CL.

Fixes #3968

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I46cfb3777d434e0d18041ea42bcd28ec4d404e06
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1216862
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+36 -12
+32 -8
cmd/cue/cmd/testdata/script/issue3968.txtar
··· 1 - ! exec cue def ./a 2 - stderr 'panic: not a string label' 1 + exec cue def ./a 2 + cmp stdout a-stdout 3 3 4 - ! exec cue def ./b 5 - stderr 'panic: not a string label' 4 + exec cue def ./b 5 + cmp stdout b-stdout 6 6 7 - ! exec cue def ./c 8 - stderr 'panic: not a string label' 7 + exec cue def ./c 8 + cmp stdout c-stdout 9 9 10 - ! exec cue def ./d 11 - stderr 'panic: not a string label' 10 + exec cue def ./d 11 + cmp stdout d-stdout 12 12 13 + -- a-stdout -- 14 + package a 15 + 16 + import #s "strings" 17 + 18 + x: #s.ToUpper("foo") 19 + -- b-stdout -- 20 + package b 21 + 22 + import _s "strings" 23 + 24 + x: _s.ToUpper("foo") 25 + -- c-stdout -- 26 + package c 27 + 28 + import "test.example/other1:_x" 29 + 30 + _x 31 + -- d-stdout -- 32 + package d 33 + 34 + import "test.example/other2:#x" 35 + 36 + #x 13 37 -- cue.mod/module.cue -- 14 38 module: "test.example" 15 39 language: version: "v0.11.0"
+4 -4
internal/core/export/adt.go
··· 484 484 485 485 case *adt.ImportReference: 486 486 importPath := x.ImportPath.StringValue(e.index) 487 + info := ast.ParseImportPath(importPath) 487 488 spec := ast.NewImport(nil, importPath) 488 489 489 - info, _ := astutil.ParseImportSpec(spec) 490 - name := info.PkgName 490 + name := info.Qualifier 491 491 if x.Label != 0 { 492 - name = x.Label.StringValue(e.index) 493 - if name != info.PkgName { 492 + name = x.Label.IdentString(e.index) 493 + if name != info.Qualifier { 494 494 spec.Name = ast.NewIdent(name) 495 495 } 496 496 }