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

Propagate uint32 arguments types in ast #432

Closed
hesining opened this issue Sep 5, 2023 · 7 comments · Fixed by #438
Closed

Propagate uint32 arguments types in ast #432

hesining opened this issue Sep 5, 2023 · 7 comments · Fixed by #438
Labels

Comments

@hesining
Copy link
Contributor

hesining commented Sep 5, 2023

package main

import (
	"fmt"
	"github.com/antonmedv/expr"
)

type Tweet struct {
	Len int
}

type Env struct {
	Tweets []Tweet
}

func (e *Env) IsTestXXX(objID uint32) (rslt bool) {
	fmt.Println(objID)
	return true
}

func main() {
	code := `IsTestXXX(111)`

	env := &Env{
		Tweets: []Tweet{{42}, {98}, {69}},
	}

	program, err := expr.Compile(code, expr.Env(env))
	if err != nil {
		panic(err)
	}

	fmt.Println(program.Source.Content())

	output, err := expr.Run(program, env)
	if err != nil {
		panic(err)
	}

	fmt.Println(output)
}

receve error msg

panic: cannot use int as argument (type uint32) to call IsTestXXX  (1:11)
 | IsTestXXX(111)                                                        
 | ..........^    
@antonmedv
Copy link
Member

Right now Expr if it sees \d+ assumes that it is int. If a function takes float64, Expr will convert this int to float64 as well. We can add the same logic for other types like uint32.

@antonmedv antonmedv changed the title a panic occur when call method with the newest version Propagate uint32 arguments types in ast Sep 6, 2023
@hesining
Copy link
Contributor Author

hesining commented Sep 7, 2023

Right now Expr if it sees \d+ assumes that it is int. If a function takes float64, Expr will convert this int to float64 as well. We can add the same logic for other types like uint32.

OK, I think I can try to fix it , give me some time.

@hesining
Copy link
Contributor Author

hesining commented Sep 8, 2023

#438

i fix it here, please check the code.

@hesining
Copy link
Contributor Author

hesining commented Sep 8, 2023

@antonmedv
There are some errors reported by fuzz. Can you help me deal with them? There should be no problem with the code.

@antonmedv
Copy link
Member

Will take a look

@hesining
Copy link
Contributor Author

hesining commented Sep 11, 2023

Will take a look

the code passed the verification, please take a look. @antonmedv

#438

@antonmedv
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants