codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

CFML: `createObject("component", "dotted.path")` creates no `instantiates` edge and gives no type to the chained receiver

Open HarryMuc opened this issue 1 month ago • 2 comments

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 instantiates edge to contens/core/queue/batchcontext.cfc
  • init in unresolved_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 instantiates edge, resolved with the same dotted-path rules as extends
  • 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.

HarryMuc avatar Oct 19 '26 09:10 HarryMuc

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.

colbymchenry avatar Oct 23 '26 11:10 colbymchenry

Thanks a lot for the solution!

HarryMuc avatar Oct 28 '26 08:10 HarryMuc