-
Notifications
You must be signed in to change notification settings - Fork 8
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: check for invalid function calls into external modules #1702
Conversation
|
||
if lhsType, ok := pctx.pkg.TypesInfo.TypeOf(selExpr.X).(*types.Named); ok && lhsType.Obj().Pkg().Path() == ftlPkgPath { | ||
// Calling a function on an FTL type | ||
if lhsType.Obj().Name() == ftlTopicHandleTypeName && selExpr.Sel.Name == "Publish" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for github.com/TBD54566975/ftl/go-runtime/ftl
and TopicHandle
separately because the actual full name also includes [AnEventType]
, which we don't care about
// checks if the is directly: | ||
// - calling external verbs | ||
// - publishing to an external module's topic | ||
func validateCallExpr(pctx *parseContext, node *ast.CallExpr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do want this to be recursive at some point, such that if you call a function that calls a verb, we can track that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should already be checking this case because we aren't just checking within functions defined as verbs:
//ftl:verb
func Verb(...) (...) {
helper()
...
}
func helper() {
externalmodule.Verb() // <--- Error here
}
if lhsIsExternal && strings.HasPrefix(lhsPkgPath, "ftl/") { | ||
if _, ok := pctx.pkg.TypesInfo.TypeOf(selExpr.Sel).(*types.Signature); ok { | ||
// can not call functions in external modules directly | ||
pctx.errors.add(errorf(node, "can not call verbs in other modules directly: use ftl.Call(…) instead")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
…l verbs # Conflicts: # go-runtime/compile/schema_test.go
d5ee26f
to
24126bc
Compare
Closes #1640
Checks for:
ftl.Call(...)
Both of these compile-time checks are not fool proof, any indirection will mean these checks don't catch it. But it is good to catch what we can.
eg:
Added a separate issue for this for pubsub as it may not be as high a priority: #1703