CFML: `createObject("component", "dotted.path")` creates no `instantiates` edge and gives no type to the chained receiver
Summary
new foo.bar.Baz() produces an instantiates edge. The equally common createObject form does not, and older code uses it more often than new.
<cfset var oContext = createObject("component", "contenscms.core.queue.batchcontext").init()>
For this line (contens/api/v2/contens/batch/collection.cfc:33) the index has:
- no
instantiatesedge tocontens/core/queue/batchcontext.cfc initinunresolved_refs
Numbers from our project
| Pattern | Occurrences | instantiates edges |
|---|---|---|
new a.b.C(...) |
158 | 160 (all instantiates edges under contens/) |
createObject("component", "<literal>") |
417 | 0 |
No instantiates edge in the index has a dotted ref name.
Expected
When the second argument is a string literal, treat createObject("component", "a.b.c") like new a.b.c():
- create an
instantiatesedge, resolved with the same dotted-path rules asextends - type the receiver of a chained
.init(...)and the assigned variable as that component, so the receiver inference from #1155 can use it
The one-argument form createObject("a.b.c") (supported by Lucee and ACF) could be handled the same way.
Thanks for the report!
#2841 is merged to main. createObject("component", "a.b.c") and the one-argument createObject("a.b.c") now link to the component they create, found by its path the way extends finds one, just as new a.b.c() does.
A call chained onto the new object, like createObject(…).init() or new a.b.c().init(), now links to that component's own init or the one it inherits, instead of whichever init the name matched first. Variables assigned from createObject were already typed, so calls on them keep working as before.
It ships in the next release; re-index after upgrading.
Thanks a lot for the solution!