Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/comple: drop support for old-style aliases
Browse files Browse the repository at this point in the history
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 <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 28, 2021
1 parent 17d4e16 commit 5cd76bb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cue/testdata/compile/scope.txtar
Expand Up @@ -26,7 +26,7 @@ e & { // Is this allowed? Probably not as per comprehension rule (ref fixes.)
{X=["foo"]: b: X | null}
{[Y="bar"]: b: Y}

B = {open: int}
let B = {open: int}
f: B

schema: {
Expand Down
2 changes: 1 addition & 1 deletion cuego/examples_test.go
Expand Up @@ -60,7 +60,7 @@ func ExampleConstrain() {
}

err := cuego.Constrain(&Config{}, `{
jsonFile = =~".json$"
let jsonFile = =~".json$"
// Filename must be defined and have a .json extension
Filename: jsonFile
Expand Down
Expand Up @@ -4,17 +4,17 @@ import "encoding/yaml"

configMap: alertmanager: {
"alerts.yaml": yaml.Marshal(alerts_yaml)
alerts_yaml = {
let alerts_yaml = {
receivers: [{
name: "pager"
// email_configs:
// - to: 'team-X+alerts-critical@example.org'
slack_configs: [{
channel: "#cloudmon"
text: """
{{ range .Alerts }}{{ .Annotations.description }}
{{ end }}
"""
{{ range .Alerts }}{{ .Annotations.description }}
{{ end }}
"""
send_resolved: true
}]
}]
Expand Down
Expand Up @@ -4,7 +4,7 @@ import "encoding/yaml"

configMap: prometheus: {
"alert.rules": yaml.Marshal(alert_rules)
alert_rules = {
let alert_rules = {
groups: [{
name: "rules.yaml"
rules: [{
Expand Down Expand Up @@ -44,7 +44,7 @@ configMap: prometheus: {
}]
}
"prometheus.yml": yaml.Marshal(prometheus_yml)
prometheus_yml = {
let prometheus_yml = {
global: scrape_interval: "15s"
rule_files: ["/etc/prometheus/alert.rules"]
alerting: alertmanagers: [{
Expand Down
18 changes: 7 additions & 11 deletions internal/core/compile/compile.go
Expand Up @@ -410,7 +410,7 @@ func (c *compiler) resolve(n *ast.Ident) adt.Expr {

switch n.Node.(type) {
// Local expressions
case *ast.LetClause, *ast.Alias:
case *ast.LetClause:
entry := c.lookupAlias(k, n)

return &adt.LetReference{
Expand All @@ -419,6 +419,8 @@ func (c *compiler) resolve(n *ast.Ident) adt.Expr {
Label: label,
X: entry.expr,
}

// TODO: handle new-style aliases
}

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

case *ast.Alias:
a := aliasEntry{
label: (*deprecatedAliasScope)(x),
srcExpr: x.Expr,
source: x,
}
c.insertAlias(x.Ident, a)
c.errf(x, "old-style alias no longer supported: use let clause.\nuse cue fix to update.")
}
}

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

// Handled in addLetDecl.
case *ast.LetClause, *ast.Alias:
case *ast.LetClause:
// case: *ast.Alias:

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

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

Expand Down
8 changes: 0 additions & 8 deletions internal/core/compile/label.go
Expand Up @@ -145,11 +145,3 @@ func (l *letScope) labelString() string {
// TODO: include more info in square brackets.
return "let[]"
}

// TODO(legacy): remove
type deprecatedAliasScope ast.Alias

func (l *deprecatedAliasScope) labelString() string {
// TODO: include more info in square brackets.
return "let[]"
}

0 comments on commit 5cd76bb

Please sign in to comment.