Skip to content

Commit 5cd76bb

Browse files
committed
internal/core/comple: drop support for old-style aliases
These are still parsed, which: 1) will allow cue fix to work for now 2) allow the parsing to be coopted for aliases to embeddings. Catches a few cases where the old syntax was still used. Change-Id: I8b9504d824e271d6744851c61fe2651ace38496e Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9503 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 17d4e16 commit 5cd76bb

File tree

6 files changed

+15
-27
lines changed

6 files changed

+15
-27
lines changed

cue/testdata/compile/scope.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ e & { // Is this allowed? Probably not as per comprehension rule (ref fixes.)
2626
{X=["foo"]: b: X | null}
2727
{[Y="bar"]: b: Y}
2828

29-
B = {open: int}
29+
let B = {open: int}
3030
f: B
3131

3232
schema: {

cuego/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func ExampleConstrain() {
6060
}
6161

6262
err := cuego.Constrain(&Config{}, `{
63-
jsonFile = =~".json$"
63+
let jsonFile = =~".json$"
6464
6565
// Filename must be defined and have a .json extension
6666
Filename: jsonFile

doc/tutorial/kubernetes/manual/services/mon/alertmanager/configmap.cue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import "encoding/yaml"
44

55
configMap: alertmanager: {
66
"alerts.yaml": yaml.Marshal(alerts_yaml)
7-
alerts_yaml = {
7+
let alerts_yaml = {
88
receivers: [{
99
name: "pager"
1010
// email_configs:
1111
// - to: '[email protected]'
1212
slack_configs: [{
1313
channel: "#cloudmon"
1414
text: """
15-
{{ range .Alerts }}{{ .Annotations.description }}
16-
{{ end }}
17-
"""
15+
{{ range .Alerts }}{{ .Annotations.description }}
16+
{{ end }}
17+
"""
1818
send_resolved: true
1919
}]
2020
}]

doc/tutorial/kubernetes/manual/services/mon/prometheus/configmap.cue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "encoding/yaml"
44

55
configMap: prometheus: {
66
"alert.rules": yaml.Marshal(alert_rules)
7-
alert_rules = {
7+
let alert_rules = {
88
groups: [{
99
name: "rules.yaml"
1010
rules: [{
@@ -44,7 +44,7 @@ configMap: prometheus: {
4444
}]
4545
}
4646
"prometheus.yml": yaml.Marshal(prometheus_yml)
47-
prometheus_yml = {
47+
let prometheus_yml = {
4848
global: scrape_interval: "15s"
4949
rule_files: ["/etc/prometheus/alert.rules"]
5050
alerting: alertmanagers: [{

internal/core/compile/compile.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func (c *compiler) resolve(n *ast.Ident) adt.Expr {
410410

411411
switch n.Node.(type) {
412412
// Local expressions
413-
case *ast.LetClause, *ast.Alias:
413+
case *ast.LetClause:
414414
entry := c.lookupAlias(k, n)
415415

416416
return &adt.LetReference{
@@ -419,6 +419,8 @@ func (c *compiler) resolve(n *ast.Ident) adt.Expr {
419419
Label: label,
420420
X: entry.expr,
421421
}
422+
423+
// TODO: handle new-style aliases
422424
}
423425

424426
if n.Scope == nil {
@@ -507,12 +509,7 @@ func (c *compiler) markAlias(d ast.Decl) {
507509
c.insertAlias(x.Ident, a)
508510

509511
case *ast.Alias:
510-
a := aliasEntry{
511-
label: (*deprecatedAliasScope)(x),
512-
srcExpr: x.Expr,
513-
source: x,
514-
}
515-
c.insertAlias(x.Ident, a)
512+
c.errf(x, "old-style alias no longer supported: use let clause.\nuse cue fix to update.")
516513
}
517514
}
518515

@@ -609,7 +606,8 @@ func (c *compiler) decl(d ast.Decl) adt.Decl {
609606
}
610607

611608
// Handled in addLetDecl.
612-
case *ast.LetClause, *ast.Alias:
609+
case *ast.LetClause:
610+
// case: *ast.Alias:
613611

614612
case *ast.CommentGroup:
615613
// Nothing to do for a free-floating comment group.
@@ -648,9 +646,7 @@ func (c *compiler) addLetDecl(d ast.Decl) {
648646
c.updateAlias(x.Ident, expr)
649647

650648
case *ast.Alias:
651-
// TODO(legacy): deprecated, remove this use of Alias
652-
expr := c.labeledExpr(nil, (*deprecatedAliasScope)(x), x.Expr)
653-
c.updateAlias(x.Ident, expr)
649+
c.errf(x, "old-style alias no longer supported: use let clause.\nuse cue fix to update.")
654650
}
655651
}
656652

internal/core/compile/label.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,3 @@ func (l *letScope) labelString() string {
145145
// TODO: include more info in square brackets.
146146
return "let[]"
147147
}
148-
149-
// TODO(legacy): remove
150-
type deprecatedAliasScope ast.Alias
151-
152-
func (l *deprecatedAliasScope) labelString() string {
153-
// TODO: include more info in square brackets.
154-
return "let[]"
155-
}

0 commit comments

Comments
 (0)