sub components

G’day. Using Lucee 6.2

I am keen to develop using sub components. I am giving it a go but noticing something that may need tweaking - either in the compiler or my understanding.

  1. sub component init and this scope

If I set the scene. In comp,cfc:

component {
    public comp function init() {
        variables.mySub = new comp$sub();
        return this;
    }
}

component name="sub" {
    // can't do this with the return type being the sub component name, as it 
    // tries to cast this to the main component type 
    // has to be public any function init() - which works and does return the sub type
    public sub function init() {
        return this;    
    }
}

In comptest.cfm:

oC = new comp();

error message:
The function [init] has an invalid return value , [Cannot cast Object type [Component comp] to a value of type [sub]]

Thanks for trying sub components! I can reproduce this on 6.2, 7.0 and 7.1. this really is your sub component. The problem is that Lucee only knows it by its full name comp$sub, so the short name sub in the return type doesn’t match. The error message mixing in comp makes that confusing. I’ve filed LDEV-6571.

For now, use the full name as the type: public comp$sub function init() { return this; }. That works on 6.2 and later, and it keeps the type check, unlike any.

Thanks, that does indeed allow proper typing for the sub component.

I had 2 more things to raise:

  1. an enhancement request for getComponentMetadata:
    getComponentmetadata("comp$sub")); // works
    getComponentMetaData("comp");     // but this does not return any sub component metadata, and IMO it should return sub component name(s) in an array or similar.
  1. properties in sub components:

In application.cfc:

this.invokeImplicitAccessor = true; 

In comp.cfc:

component {
    
    public comp function init(){
        var tmpP1;
        variables.mySub = new comp$sub();
       
        tmpP1 = variables.mySub.p1;  // <--- error here
        
        return this;
    }
}

component name="sub" {
    property name="p1" type="string" default="";

    public comp$sub function init(){
        variables.p1 = "hello there";
        return this;
    }
    
    public string function getP1() {
        return variables.p1;
    }
}

This generates an error:
Message: Component [comp$sub] has no accessible Member with name [P1]
Detail: enable [trigger data member] in administrator to also invoke getters and setters

Thanks, I could reproduce both on 6.2 through 8.0.

  1. invokeImplicitAccessor in a sub component: this is a bug. Inside the parent file, Lucee wrongly treats the sub component as private, because both share the same source file, so the implicit getter isn’t created. I filed it as LDEV-6575, and the fix will go into 7.1.
  2. Listing sub components in getComponentMetadata: that makes sense as an enhancement. I filed it as LDEV-6574 for 8.0, with the idea of adding a subComponents key.

Thanks.