From 1bae160796461066a07ca1721c4688db0d5ce567 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 21 Dec 2016 11:31:53 -0800 Subject: [PATCH] vendor: update HIL Fixes #10847 Fixes #10778 --- .../github.com/hashicorp/hil/check_types.go | 36 +++++++++++-------- vendor/vendor.json | 18 +++++----- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/vendor/github.com/hashicorp/hil/check_types.go b/vendor/github.com/hashicorp/hil/check_types.go index 9346c4cf1..a8ca44e06 100644 --- a/vendor/github.com/hashicorp/hil/check_types.go +++ b/vendor/github.com/hashicorp/hil/check_types.go @@ -119,7 +119,9 @@ func (tc *typeCheckArithmetic) TypeCheck(v *TypeCheck) (ast.Node, error) { switch tc.n.Op { case ast.ArithmeticOpLogicalAnd, ast.ArithmeticOpLogicalOr: return tc.checkLogical(v, exprs) - case ast.ArithmeticOpEqual, ast.ArithmeticOpNotEqual, ast.ArithmeticOpLessThan, ast.ArithmeticOpGreaterThan, ast.ArithmeticOpGreaterThanOrEqual, ast.ArithmeticOpLessThanOrEqual: + case ast.ArithmeticOpEqual, ast.ArithmeticOpNotEqual, + ast.ArithmeticOpLessThan, ast.ArithmeticOpGreaterThan, + ast.ArithmeticOpGreaterThanOrEqual, ast.ArithmeticOpLessThanOrEqual: return tc.checkComparison(v, exprs) default: return tc.checkNumeric(v, exprs) @@ -135,20 +137,11 @@ func (tc *typeCheckArithmetic) checkNumeric(v *TypeCheck, exprs []ast.Type) (ast mathFunc := "__builtin_IntMath" mathType := ast.TypeInt for _, v := range exprs { - exit := true - switch v { - case ast.TypeInt: - mathFunc = "__builtin_IntMath" - mathType = v - case ast.TypeFloat: + // We assume int math but if we find ANY float, the entire + // expression turns into floating point math. + if v == ast.TypeFloat { mathFunc = "__builtin_FloatMath" mathType = v - default: - exit = false - } - - // We found the type, so leave - if exit { break } } @@ -193,7 +186,6 @@ func (tc *typeCheckArithmetic) checkNumeric(v *TypeCheck, exprs []ast.Type) (ast } func (tc *typeCheckArithmetic) checkComparison(v *TypeCheck, exprs []ast.Type) (ast.Node, error) { - if len(exprs) != 2 { // This should never happen, because the parser never produces // nodes that violate this. @@ -220,6 +212,22 @@ func (tc *typeCheckArithmetic) checkComparison(v *TypeCheck, exprs []ast.Type) ( ) } + // For non-equality comparisons, we will do implicit conversions to + // integer types if possible. In this case, we need to go through and + // determine the type of comparison we're doing to enable the implicit + // conversion. + if tc.n.Op != ast.ArithmeticOpEqual && tc.n.Op != ast.ArithmeticOpNotEqual { + compareFunc = "__builtin_IntCompare" + compareType = ast.TypeInt + for _, expr := range exprs { + if expr == ast.TypeFloat { + compareFunc = "__builtin_FloatCompare" + compareType = ast.TypeFloat + break + } + } + } + // Verify (and possibly, convert) the args for i, arg := range exprs { if arg != compareType { diff --git a/vendor/vendor.json b/vendor/vendor.json index ed3afd27f..03c4dc508 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1613,28 +1613,28 @@ "revisionTime": "2016-11-30T20:58:18Z" }, { - "checksumSHA1": "xONRNgLDc5OqCUmyDN3iBRKmKB0=", + "checksumSHA1": "2Nrl/YKrmowkRgCDLhA6UTFgYEY=", "path": "github.com/hashicorp/hil", - "revision": "60db937199ba6f67251aa038cec18ce36a951312", - "revisionTime": "2016-12-09T17:20:46Z" + "revision": "5b8d13c8c5c2753e109fab25392a1dbfa2db93d2", + "revisionTime": "2016-12-21T19:20:42Z" }, { "checksumSHA1": "oZ2a2x9qyHqvqJdv/Du3LGeaFdA=", "path": "github.com/hashicorp/hil/ast", - "revision": "60db937199ba6f67251aa038cec18ce36a951312", - "revisionTime": "2016-12-09T17:20:46Z" + "revision": "5b8d13c8c5c2753e109fab25392a1dbfa2db93d2", + "revisionTime": "2016-12-21T19:20:42Z" }, { "checksumSHA1": "P5PZ3k7SmqWmxgJ8Q0gLzeNpGhE=", "path": "github.com/hashicorp/hil/parser", - "revision": "60db937199ba6f67251aa038cec18ce36a951312", - "revisionTime": "2016-12-09T17:20:46Z" + "revision": "5b8d13c8c5c2753e109fab25392a1dbfa2db93d2", + "revisionTime": "2016-12-21T19:20:42Z" }, { "checksumSHA1": "DC1k5kOua4oFqmo+JRt0YzfP44o=", "path": "github.com/hashicorp/hil/scanner", - "revision": "60db937199ba6f67251aa038cec18ce36a951312", - "revisionTime": "2016-12-09T17:20:46Z" + "revision": "5b8d13c8c5c2753e109fab25392a1dbfa2db93d2", + "revisionTime": "2016-12-21T19:20:42Z" }, { "path": "github.com/hashicorp/logutils",