Skip to content

Commit

Permalink
Fix for comprehension type-checks against invalid range types. (#276)
Browse files Browse the repository at this point in the history
* Fix for comprehension type-checks against invalid range types
  • Loading branch information
TristonianJones authored Oct 23, 2019
1 parent ca29364 commit ecaec2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ func (c *checker) checkComprehension(e *exprpb.Expr) {
varType = decls.Dyn
default:
c.errors.notAComprehensionRange(c.location(comp.IterRange), rangeType)
varType = decls.Error
}

// Create a scope for the comprehension since it has a local accumulation variable.
Expand Down
36 changes: 36 additions & 0 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,42 @@ _==_(size(x~google.expr.proto3.test.TestAllTypes^x.map_int64_nested_type
`,
Type: decls.Bool,
},
{
I: `x.all(y, y == true)`,
Env: env{
idents: []*exprpb.Decl{
decls.NewIdent("x", decls.Bool, nil),
},
},
R: `
__comprehension__(
// Variable
y,
// Target
x~bool^x,
// Accumulator
__result__,
// Init
true~bool,
// LoopCondition
@not_strictly_false(
__result__~bool^__result__
)~bool^not_strictly_false,
// LoopStep
_&&_(
__result__~bool^__result__,
_==_(
y~!error!^y,
true~bool
)~bool^equals
)~bool^logical_and,
// Result
__result__~bool^__result__)~bool
`,
Error: `ERROR: <input>:1:1: expression of type 'bool' cannot be range of a comprehension (must be list, map, or dynamic)
| x.all(y, y == true)
| ^`,
},
{
I: `x.repeated_int64.map(x, double(x))`,
Env: env{
Expand Down

0 comments on commit ecaec2d

Please sign in to comment.