forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): fix type equality with native values in binary expressions (
gnolang#2016) fixes gnolang#1966 <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
- Loading branch information
Showing
6 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package gnolang | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPreprocess_BinaryExpressionOneNative(t *testing.T) { | ||
pn := NewPackageNode("time", "time", nil) | ||
pn.DefineGoNativeValue("Millisecond", time.Millisecond) | ||
pn.DefineGoNativeValue("Second", time.Second) | ||
pn.DefineGoNativeType(reflect.TypeOf(time.Duration(0))) | ||
pv := pn.NewPackage() | ||
store := gonativeTestStore(pn, pv) | ||
store.SetBlockNode(pn) | ||
|
||
const src = `package main | ||
import "time" | ||
func main() { | ||
var a int64 = 2 | ||
println(time.Second * a) | ||
}` | ||
n := MustParseFile("main.go", src) | ||
|
||
defer func() { | ||
err := recover() | ||
assert.Contains(t, fmt.Sprint(err), "incompatible types in binary expression") | ||
}() | ||
Preprocess(store, pn, n) | ||
} | ||
|
||
func TestPreprocess_BinaryExpressionBothNative(t *testing.T) { | ||
pn := NewPackageNode("time", "time", nil) | ||
pn.DefineGoNativeValue("March", time.March) | ||
pn.DefineGoNativeValue("Wednesday", time.Wednesday) | ||
pn.DefineGoNativeType(reflect.TypeOf(time.Month(0))) | ||
pn.DefineGoNativeType(reflect.TypeOf(time.Weekday(0))) | ||
pv := pn.NewPackage() | ||
store := gonativeTestStore(pn, pv) | ||
store.SetBlockNode(pn) | ||
|
||
const src = `package main | ||
import "time" | ||
func main() { | ||
println(time.March * time.Wednesday) | ||
}` | ||
n := MustParseFile("main.go", src) | ||
|
||
defer func() { | ||
err := recover() | ||
assert.Contains(t, fmt.Sprint(err), "incompatible types in binary expression") | ||
}() | ||
Preprocess(store, pn, n) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
var a int64 = 2 | ||
fmt.Println(time.Second * a) | ||
} | ||
|
||
// Error: | ||
// main/files/time16_native.gno:10: incompatible types in binary expression: go:time.Duration MUL int64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters