Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): annotate specific reason a value does not implement an interface #2492

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

Villaquiranm
Copy link
Contributor

@Villaquiranm Villaquiranm commented Jul 3, 2024

Related to #1684 .
This is a first draft that will increment the amount of information Gno returns in the case of an struct not implementing a defined interface.

First Case

A non defined function on interface

package main

type Car interface{
	Run(speed int)
}

type Toyota struct {}
func main(){
	var car Car = &Toyota{}
}

Before we had something like:
panic: *main.Toyota does not implement main.Car [recovered]
now:
panic: *main.Toyota does not implement main.Car (missing method Run) [recovered]

Second Case

A defined function with bad type on function signature

package main

type Car interface{
	Run(speed int)
}

type Toyota struct {}

func (toyota *Toyota) Run(quick bool){
}

func main(){
	var car Car = &Toyota{}
}

Before we had something like:
panic: *main.Toyota does not implement main.Car [recovered]
now:
panic: *main.Toyota does not implement main.Car (wrong type for method Run) [recovered]

Third Case

A defined function with a pointer receiver but not pointer variable

package main

type Car interface {
	Run()
}

type Toyota struct {
}

func (t *Toyota) Run() {

}

func main() {
	var car Car = Toyota{}
}

Before we had something like:
panic: *main.Toyota does not implement main.Car [recovered]
now:
panic: main.Toyota does not implement main.Car (method Run has pointer receiver):

Contributors' checklist...
  • 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, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jul 3, 2024
Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Project coverage is 55.03%. Comparing base (0a662c4) to head (bb3bc87).

Files Patch % Lines
gnovm/pkg/gnolang/types.go 70.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2492      +/-   ##
==========================================
+ Coverage   55.01%   55.03%   +0.01%     
==========================================
  Files         595      595              
  Lines       79662    79665       +3     
==========================================
+ Hits        43828    43842      +14     
+ Misses      32518    32509       -9     
+ Partials     3316     3314       -2     
Flag Coverage Δ
contribs/gnodev 26.00% <ø> (+0.34%) ⬆️
contribs/gnofaucet 14.46% <ø> (ø)
contribs/gnokeykc 0.00% <ø> (ø)
contribs/gnomd 0.00% <ø> (ø)
gno.land 64.24% <ø> (ø)
gnovm 60.33% <84.21%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Villaquiranm Villaquiranm force-pushed the 1684-anotate-does-not-implement branch from 3197a35 to 115c7dc Compare July 3, 2024 20:27
@Villaquiranm Villaquiranm changed the title Anotate specific reason an interface does not implements x fix: Anotate specific reason an interface does not implements x Jul 3, 2024
@Villaquiranm Villaquiranm force-pushed the 1684-anotate-does-not-implement branch from 115c7dc to 21876b5 Compare July 3, 2024 21:08
@Villaquiranm Villaquiranm marked this pull request as ready for review July 3, 2024 21:25
@Villaquiranm Villaquiranm force-pushed the 1684-anotate-does-not-implement branch from 21876b5 to a09759d Compare July 3, 2024 21:39
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a bit of reorganization needed

gnovm/pkg/gnolang/types.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/types.go Show resolved Hide resolved
@thehowl thehowl changed the title fix: Anotate specific reason an interface does not implements x fix(gnovm): annotate specific reason a value does not implement an interface Jul 10, 2024
@Villaquiranm Villaquiranm force-pushed the 1684-anotate-does-not-implement branch from a09759d to 09e0331 Compare July 11, 2024 10:44
@Villaquiranm Villaquiranm force-pushed the 1684-anotate-does-not-implement branch from 09e0331 to bb3bc87 Compare July 11, 2024 10:48
@petar-dambovaliev petar-dambovaliev self-requested a review July 16, 2024 04:56
@thehowl thehowl merged commit 447b763 into gnolang:master Jul 17, 2024
89 checks passed
@omarsy omarsy deleted the 1684-anotate-does-not-implement branch July 17, 2024 15:32
gfanton pushed a commit to gfanton/gno that referenced this pull request Jul 23, 2024
…terface (gnolang#2492)

Related to gnolang#1684 .
This is a first draft that will increment the amount of information Gno
returns in the case of an struct not implementing a defined interface.

### First Case
`A non defined function on interface`
```go
package main

type Car interface{
	Run(speed int)
}

type Toyota struct {}
func main(){
	var car Car = &Toyota{}
}
```
**Before** we had something like:
`panic: *main.Toyota does not implement main.Car [recovered]`
**now**:
`panic: *main.Toyota does not implement main.Car (missing method Run)
[recovered]`

### Second Case
`A defined function with bad type on function signature`
```go
package main

type Car interface{
	Run(speed int)
}

type Toyota struct {}

func (toyota *Toyota) Run(quick bool){
}

func main(){
	var car Car = &Toyota{}
}
```
**Before** we had something like:
`panic: *main.Toyota does not implement main.Car [recovered]`
**now**:
`panic: *main.Toyota does not implement main.Car (wrong type for method
Run) [recovered]`

### Third Case
`A defined function with a pointer receiver but not pointer variable`
```go
package main

type Car interface {
	Run()
}

type Toyota struct {
}

func (t *Toyota) Run() {

}

func main() {
	var car Car = Toyota{}
}
```
**Before** we had something like:
`panic: *main.Toyota does not implement main.Car [recovered]`
**now**:
`panic: main.Toyota does not implement main.Car (method Run has pointer
receiver):`

<!-- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants