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

dsl/fluent: improve Var.Type doc #81

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dsl/fluent/dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ type Var struct {
Addressable bool

// Type is a type of a matched expr.
//
// For function call expressions, a type is a function result type,
// but for a function expression itself it's a *types.Signature.
//
// Suppose we have a `a.b()` expression:
// `$x()` m["x"].Type is `a.b` function type
Copy link
Contributor

@sebastien-rosset sebastien-rosset Sep 30, 2020

Choose a reason for hiding this comment

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

ok, that's great. I'm trying to understand what the Where argument value is supposed to be in the case of a function type. Is it the output of reflect.TypeOf($x).String()? That does not seem to work.

For example:

   runtime.GC()
   fmt.Printf("Type: %v\n", reflect.TypeOf(runtime.GC)) // output is `func()`

How would we write m["x"].Type.Is(...)? If I type the rule below, the parser complains about parse type expr: can't convert func() type expression

m.Match(`$x($y)`).Where(m["x"].Type.Is("func()"))

Copy link
Owner Author

Choose a reason for hiding this comment

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

Now I remember that Is() method doesn't implement function types matching. Fixed in #82.

See tests for some examples.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, thank you!

// `$x` m["x"].Type is `a.b()` function call result type
Type ExprType

// Text is a captured node text as in the source code.
Expand Down