bobg / bobg/exprvals

Be smarter

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Go
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Exprvals can be a lot smarter than it currently is.

For example, by the end of this block of statements:

```go
x := "foo"
x = "bar"
```

exprvals will report that x can be `foo` or `bar`, but really it can only be `bar`. Likewise, at the call to `fmt.Println`:

```go
x := "foo"
if condition() {
x = "bar"
}
fmt.Println(x)
x = "baz"
```

exprvals will report that x can be `foo`, `bar`, or `baz`, but it can only be `foo` or `bar`.

On the other hand, in this example:

```go
var x string
for {
if condition1() {
x = "foo"
}
if condition2() {
x = "bar"
}
fmt.Println(x)
x = "baz"
}
```

x _can_ be `foo`, `bar`, or `baz` at the call to `fmt.Println`. Or maybe not - if exprvals is able to determine that the loop runs only once.

For that matter, it may be able to prune out certain if/else branches, or switch cases, which can improve its precision even further. For example, exprvals current reports that x can be `foo` or `bar` in this example, but really it can only be `foo`:

```go
x := "foo"
if false {
x = "bar"
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.