You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0004-type-deduction.md
+4-9
Original file line number
Diff line number
Diff line change
@@ -109,26 +109,21 @@ The variable must be of type String.
109
109
110
110
111
111
## Correct Inference for dependencies
112
-
Extra care has to be taken when deducing in binary expressions, with an Operator (like Plus, Minus, Multiply, Divide, In (var on lhs), NotIn (var on lhs)) where the variable type depends on the type of the other side. There are 2 special cases that have to be handled.
112
+
Extra care has to be taken when deducing in binary expressions, with an Operator (like Plus, Minus, Multiply, Divide, In (var on lhs), NotIn (var on lhs)) where the variable type depends on the type of the other side.
113
113
114
-
### Special case 1: Binary with variables on both sides
115
-
```shell Example
114
+
```shell Variables on both sides
116
115
ls | where size <$a*$b;kill$a
117
116
$a -> SyntaxShape::Int
118
117
$b -> SyntaxShape::Unit
119
118
```
120
-
121
-
At the time of traversing the AST, any deduction for any variable may not be present, and if present may not be complete. Therefore constellations in which the deduction of one variable depends on the deduction of another one (we will call these constellations 'dependencies'), have to be postponed.
122
-
123
-
### Special case 2: Binary which depends on the result type of another expression
124
-
```shell Example
119
+
```shell Variable on one side, math expression with variables on other
125
120
ls | where size <$a* ($b*$c);kill$b$c
126
121
$a -> SyntaxShape::Unit
127
122
$b -> SyntaxShape::Int
128
123
$c -> SyntaxShape::Int
129
124
```
130
-
Same as above. But this time $a also depends on the result type of ($b * $c). This dependency has to be postponed, as $b nor $c can be deduced at the point in time of traversing the AST.
131
125
126
+
At the time of traversing the AST, any deduction for any variable may not be present, and if present may not be complete. Therefore constellations in which the deduction of one variable depends on the deduction of another one (we will call these constellations 'dependencies'), have to be postponed.
132
127
133
128
As soon as the AST is traversed, the dependencies have to be resolved.
134
129
Please note: One might think of a dependency as a edge in a directed graph, with variables as nodes. Every Node with no outgoing edge is completly deduced. Every Node with an edge towards such a completly deduced node can then be inferred. Nodes with cycles (e.G. `ls | where size < $a * $b` $a depends on $b, $b depends on $a) can't be deduced completly.
0 commit comments