Skip to content

Commit

Permalink
internal/core/adt: allow errors in inline structs
Browse files Browse the repository at this point in the history
Consider the below example:

	#Step: (#Job & {opt: _}).opt
	#Job: matchN(1, [#NormalJob])
	#NormalJob: {
		req!: int
		opt?: run?: string
	}

The inline struct of field #Step is erroneous, as it
does not satisfy the validator. However, V2 allowed
accessing opt and bypass the error. This change
allows this for V3 as well.

One supportive argument for this choice is that V3
does allow selecting into an erroneous struct in
this situation:

	#Step: #Job.opt
	#Job: matchN(1, [#NormalJob]) & {opt: _}
	#NormalJob: {
		req!: int
		opt?: run?: string
	}

This is an equivalent situation.
V3 should at least be consistent, so the choice was
to make it more compatible with V2.

This change does introduce a regression. We will
address this in a subsequent CL.

The two key fixes in this CL are the shallow
evaluation in BinaryExpr (CompleteArcsOnly), which
is what V2 did as well, and to pass the evaluation
mode to evalArcTypes.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I5307445395574f649d0cd1c6d5b309de0a87ef58
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202907
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Oct 23, 2024
1 parent 9f46e1a commit 62b21c8
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 326 deletions.
225 changes: 49 additions & 176 deletions cue/testdata/comprehensions/issue837.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,12 @@ Conjuncts: 563
Disjuncts: 30
-- out/evalalpha --
Errors:
_params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
./in.cue:55:12
./in.cue:56:22
_params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
./in.cue:55:12
./in.cue:56:15
_params.hsize.$_instances.$_instances: field not allowed:
./in.cue:33:20
./in.cue:56:2
#Configure.service.description.role: undefined field: role:
./in.cue:40:19
#DoDeploy.deployment.description.service.description.role: undefined field: role:
./in.cue:40:19
#RelabelService.out.labstr: undefined field: label:
./in.cue:51:14
_params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
./in.cue:56:15
./in.cue:29:20
./in.cue:56:17
./in.cue:61:39
_params.hsize.$_instances.$_instances: field not allowed:
./in.cue:56:15
./in.cue:56:2

Result:
(_|_){
Expand Down Expand Up @@ -141,23 +128,20 @@ Result:
}
}
service: (_|_){
// [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
// ./in.cue:55:12
// ./in.cue:56:22
// _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
// ./in.cue:55:12
// ./in.cue:56:15
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:33:20
// ./in.cue:56:2
// _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
// ./in.cue:56:15
// ./in.cue:29:20
// ./in.cue:56:17
// ./in.cue:61:39
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:56:15
// ./in.cue:56:2
// [eval]
description: (_|_){
// [eval]
let configed#2 = (#struct){
labstr: (_|_){
// [incomplete] #DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
}
}
role: (_|_){
// [eval] #DoDeploy.deployment.description.service.description.role: undefined field: role:
// ./in.cue:40:19
}
}
}
}
}
Expand All @@ -172,41 +156,15 @@ Result:
// [eval]
description: (_|_){
// [eval]
let configed#2 = (_|_){
// [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
// ./in.cue:55:12
// ./in.cue:56:22
// _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
// ./in.cue:55:12
// ./in.cue:56:15
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:33:20
// ./in.cue:56:2
// _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
// ./in.cue:56:15
// ./in.cue:29:20
// ./in.cue:56:17
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:56:15
// ./in.cue:56:2
let configed#2 = (#struct){
labstr: (_|_){
// [incomplete] #Configure.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
}
}
role: (_|_){
// [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
// ./in.cue:55:12
// ./in.cue:56:22
// _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
// ./in.cue:55:12
// ./in.cue:56:15
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:33:20
// ./in.cue:56:2
// _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
// ./in.cue:56:15
// ./in.cue:29:20
// ./in.cue:56:17
// _params.hsize.$_instances.$_instances: field not allowed:
// ./in.cue:56:15
// ./in.cue:56:2
// [eval] #Configure.service.description.role: undefined field: role:
// ./in.cue:40:19
}
}
}
Expand Down Expand Up @@ -248,35 +206,7 @@ Result:
diff old new
--- old
+++ new
@@ -1,10 +1,23 @@
Errors:
-#Configure.service.description.role: undefined field: role:
- ./in.cue:40:19
-#DoDeploy.deployment.description.service.description.role: undefined field: role:
- ./in.cue:40:19
+_params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
+ ./in.cue:55:12
+ ./in.cue:56:22
+_params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
+ ./in.cue:55:12
+ ./in.cue:56:15
+_params.hsize.$_instances.$_instances: field not allowed:
+ ./in.cue:33:20
+ ./in.cue:56:2
#RelabelService.out.labstr: undefined field: label:
./in.cue:51:14
+_params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
+ ./in.cue:56:15
+ ./in.cue:29:20
+ ./in.cue:56:17
+ ./in.cue:61:39
+_params.hsize.$_instances.$_instances: field not allowed:
+ ./in.cue:56:15
+ ./in.cue:56:2

Result:
(_|_){
@@ -13,24 +26,10 @@
@@ -13,24 +13,10 @@
ref: (#struct){
kind: (string){ "deployment" }
}
Expand All @@ -303,7 +233,7 @@ diff old new
description: (_|_){
// [incomplete] #Manifest.description: unresolved disjunction "service" | "deployment" (type string):
// ./in.cue:5:15
@@ -42,16 +41,10 @@
@@ -42,16 +28,10 @@
#KindsNames: (string){ |((string){ "service" }, (string){ "deployment" }) }
#KumoriKinds: (#struct){
deployment: (#struct){
Expand All @@ -324,7 +254,7 @@ diff old new
}
}
}
@@ -58,24 +51,7 @@
@@ -58,24 +38,7 @@
#DoDeploy: (_|_){
// [eval]
_params: (#struct){
Expand All @@ -350,7 +280,7 @@ diff old new
}
deployment: (_|_){
// [eval]
@@ -82,34 +58,30 @@
@@ -82,16 +45,10 @@
description: (_|_){
// [eval]
let dep#1 = (#struct){
Expand All @@ -371,90 +301,33 @@ diff old new
}
}
service: (_|_){
- // [eval]
- description: (_|_){
- // [eval]
@@ -98,10 +55,9 @@
// [eval]
description: (_|_){
// [eval]
- let configed#2 = (_|_){
- // [eval]
- labstr: (_|_){
+ let configed#2 = (#struct){
labstr: (_|_){
- // [eval] #DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
- // ./in.cue:51:14
- }
- }
- role: (_|_){
- // [eval] #DoDeploy.deployment.description.service.description.role: undefined field: role:
- // ./in.cue:40:19
- }
- }
+ // [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:22
+ // _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:15
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:33:20
+ // ./in.cue:56:2
+ // _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
+ // ./in.cue:56:15
+ // ./in.cue:29:20
+ // ./in.cue:56:17
+ // ./in.cue:61:39
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:56:15
+ // ./in.cue:56:2
}
}
}
@@ -125,15 +97,40 @@
+ // [incomplete] #DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
}
}
@@ -124,10 +80,9 @@
// [eval]
description: (_|_){
// [eval]
let configed#2 = (_|_){
- let configed#2 = (_|_){
- // [eval]
- labstr: (_|_){
+ let configed#2 = (#struct){
labstr: (_|_){
- // [eval] #Configure.service.description.configed.labstr: undefined field: label:
- // ./in.cue:51:14
- }
+ // [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:22
+ // _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:15
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:33:20
+ // ./in.cue:56:2
+ // _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
+ // ./in.cue:56:15
+ // ./in.cue:29:20
+ // ./in.cue:56:17
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:56:15
+ // ./in.cue:56:2
}
role: (_|_){
- // [eval] #Configure.service.description.role: undefined field: role:
- // ./in.cue:40:19
+ // [eval] _params.hsize.$_instances: conflicting values 1 and {$_instances:(>=0|*1)} (mismatched types int and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:22
+ // _params.hsize.$_instances: conflicting values >=0 and {$_instances:(>=0|*1)} (mismatched types number and struct):
+ // ./in.cue:55:12
+ // ./in.cue:56:15
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:33:20
+ // ./in.cue:56:2
+ // _params.hsize.$_instances: invalid operands {$_instances:_|_(_params.hsize.$_instances.$_instances: field not allowed)} and 0 to '>=' (type _|_ and int):
+ // ./in.cue:56:15
+ // ./in.cue:29:20
+ // ./in.cue:56:17
+ // _params.hsize.$_instances.$_instances: field not allowed:
+ // ./in.cue:56:15
+ // ./in.cue:56:2
+ // [incomplete] #Configure.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
}
}
}
}
@@ -141,9 +138,7 @@
@@ -141,9 +96,7 @@
#RelabelService: (_|_){
// [eval]
_params: (#struct){
Expand All @@ -465,7 +338,7 @@ diff old new
}
out: (_|_){
// [eval]
@@ -157,16 +152,10 @@
@@ -157,16 +110,10 @@
$_instances: (number){ |(*(int){ 1 }, (number){ >=0 }) }
}
#Deployment: (#struct){
Expand Down
16 changes: 8 additions & 8 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ issue2052.t1.#Depth: adding field #basic not allowed as field set was already re
issue2052.t1.d: adding field #basic not allowed as field set was already referenced:
./issue2052.cue:8:20
issue2052.t2.#Depth: adding field #basic not allowed as field set was already referenced:
./issue2052.cue:41:20
./issue2052.cue:46:14
issue2052.t2.d: adding field #basic not allowed as field set was already referenced:
./issue2052.cue:41:20
./issue2052.cue:46:14

Result:
(_|_){
Expand Down Expand Up @@ -354,7 +354,7 @@ Result:
// [eval]
#Depth: (_|_){
// [eval] issue2052.t2.#Depth: adding field #basic not allowed as field set was already referenced:
// ./issue2052.cue:41:20
// ./issue2052.cue:46:14
#maxiter: (int){ 4 }
#funcs: (#struct){
"4": (null){ null }
Expand Down Expand Up @@ -391,7 +391,7 @@ Result:
tree: (string){ "bar" }
d: (_|_){
// [eval] issue2052.t2.d: adding field #basic not allowed as field set was already referenced:
// ./issue2052.cue:41:20
// ./issue2052.cue:46:14
#in: (string){ "bar" }
#maxiter: (int){ 4 }
#funcs: (#struct){
Expand Down Expand Up @@ -753,9 +753,9 @@ diff old new
+issue2052.t1.d: adding field #basic not allowed as field set was already referenced:
+ ./issue2052.cue:8:20
+issue2052.t2.#Depth: adding field #basic not allowed as field set was already referenced:
+ ./issue2052.cue:41:20
+ ./issue2052.cue:46:14
+issue2052.t2.d: adding field #basic not allowed as field set was already referenced:
+ ./issue2052.cue:41:20
+ ./issue2052.cue:46:14
+
+Result:
+(_|_){
Expand Down Expand Up @@ -1000,7 +1000,7 @@ diff old new
+ // [eval]
+ #Depth: (_|_){
+ // [eval] issue2052.t2.#Depth: adding field #basic not allowed as field set was already referenced:
+ // ./issue2052.cue:41:20
+ // ./issue2052.cue:46:14
+ #maxiter: (int){ 4 }
+ #funcs: (#struct){
+ "4": (null){ null }
Expand Down Expand Up @@ -1037,7 +1037,7 @@ diff old new
+ tree: (string){ "bar" }
+ d: (_|_){
+ // [eval] issue2052.t2.d: adding field #basic not allowed as field set was already referenced:
+ // ./issue2052.cue:41:20
+ // ./issue2052.cue:46:14
+ #in: (string){ "bar" }
+ #maxiter: (int){ 4 }
+ #funcs: (#struct){
Expand Down
Loading

0 comments on commit 62b21c8

Please sign in to comment.