Skip to content

Commit

Permalink
Allow one or both conditional operands to be unknown
Browse files Browse the repository at this point in the history
In #52 we relaxed the rule that any unknown value would immediately cause
an early exit, which in turn requires the type checker for each node to
specifically deal with unknown values.

However, we missed dealing with the check that both types match in a
conditional, causing a conditional to fail if either side of it is
unknown.

This causes errors in Terraform, as described in
hashicorp/terraform#14399.
  • Loading branch information
apparentlymart committed May 12, 2017
1 parent f3681c6 commit 2840572
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions check_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (tc *typeCheckConditional) TypeCheck(v *TypeCheck) (ast.Node, error) {
}

// The types of the true and false expression must match
if trueType != falseType {
if trueType != falseType && trueType != ast.TypeUnknown && falseType != ast.TypeUnknown {

// Since passing around stringified versions of other types is
// common, we pragmatically allow the false expression to dictate
Expand Down Expand Up @@ -460,7 +460,13 @@ func (tc *typeCheckConditional) TypeCheck(v *TypeCheck) (ast.Node, error) {
}

// Result type (guaranteed to also match falseType due to the above)
v.StackPush(trueType)
if trueType == ast.TypeUnknown {
// falseType may also be unknown, but that's okay because two
// unknowns means our result is unknown anyway.
v.StackPush(falseType)
} else {
v.StackPush(trueType)
}

return tc.n, nil
}
Expand Down

0 comments on commit 2840572

Please sign in to comment.