Search code examples
coldfusioncoldfusion-9cfml

cfscript component function with object types in arguments and returntypes


I have a feeling this is a bug in CF9, from looking at this: How to specify argument attributes in CFscript? (CF9)

However, if not, I'm writing a cfscript component in CF9 (pure), and attempting to pass an argument as a type of user defined cfc.

public function init(required _lbr._core._sharing._access.accessLinkDAO oAccessLinkDAO) returntype="_lbr._core._sharing._access.accessLinkBusiness" {

But CF keeps coming back with:

You cannot use a variable reference with "." operators in this context

is this something broken with CF9 pure?


Solution

  • I have confirmed this is a bug in CF9.0 (and fixed in one of CF9.0.1 or CF9.0.2; probably 9.0.1).

    However the fix is easy. The problem is only with the dotted paths, and as @ScottStroz points out, you don't need them. This works fine:

    component {
        public accessLinkBusiness function init(required accessLinkDAO oAccessLinkDAO) {
            return this;
        }
    }
    

    I've moved the return type simply because that's just the normal place for it: it'll work as attribute too (but that syntax is just awful).

    If the CFCs you are referencing as return types or argument types aren't in the same dir as the CFC using them, use an import statement, eg in this case:

    import _lbr._core._sharing._access.*;