Tim
08/08/2022, 4:55 PMabstract
keyword that was added in cf2018. Before I go filing bugs, I want to know if what I'm doing is supposed to work.Tim
08/08/2022, 4:57 PMTim
08/08/2022, 5:00 PMabstract component accessors=true {
property string aThing;
function init() {
setAThing("default");
return this;
}
}
It complains that "Variable SETATHING is undefined."Adam Cameron
Adam Cameron
abstract
qualifier works?Tim
08/08/2022, 5:21 PM/**
* ServiceProvider.cfc
*/
component accessor=true {
property string basePath;
property string applicationArea;
public ServiceProvider function init() {
setBasePath("");
setApplicationArea("");
return this;
}
more methods
}
I'm implementing some new Service Providers that share a bunch of common code, so I decided to abstract it to a common component
/**
* AbstractDocumentProvider
*/
abstract component extends="ServiceProvider" {
stuff in here
}
/**
* ClientDocumentProvider
*/
component extends="AbstractDocumentProvider" {
concrete implementation
}
Tim
08/08/2022, 5:22 PMabstract
was a syntax error in AbstractDocumentProvider.Tim
08/08/2022, 5:23 PM/**
* ServiceProvider.cfc
*/
abstract component accessor=true {
property string basePath;
property string applicationArea;
public ServiceProvider function init() {
setBasePath("");
setApplicationArea("");
return this;
}
more methods
}
No other changes. Just added the asbstract keyword.Tim
08/08/2022, 5:24 PMTim
08/08/2022, 5:25 PMseancorfield
seancorfield
Tim
08/08/2022, 5:37 PMseancorfield
seancorfield
Adam Cameron
And now I'm getting this error that setBasePath is undefined.Depending on how accurate your code is compared to what you show us, this will be because you have
accessor=true
. Note it should be accessorS
.Adam Cameron
// Base.cfc
component {}
// AbstractIntermediary.cfc
abstract component extends=Base accessors=true {
property string someProp;
function init() {
setSomeProp("default")
}
}
// SubImplementation.cfc
component extends=AbstractIntermediary {}
<cfscript>
// test.cfm
o = new SubImplementation()
writeDump(o.getSomeProp())
</cfscript>
Which seems like a reasonable SSCCE of what you are desscribing, and it works fine. On CF2021. How does it work for you?Adam Cameron
Tim
08/08/2022, 8:30 PMaccessor
vs accessors
issue was just when i typed it in here, and doesn't exist in the real code.Tim
08/08/2022, 8:56 PMTim
08/08/2022, 9:07 PM// Base.cfc
component accessors=true {
property string someProp;
function init() {
setSomeProp("default");
}
}
// AbstractIntermediary.cfc
abstract component extends=Base {}
// SubImplementation.cfc
component extends=AbstractIntermediary {}
<cfscript>
// test.cfm
o = new SubImplementation()
writeDump(o.getSomeProp())
</cfscript>
Tim
08/08/2022, 9:10 PMabstract
too.)Tim
08/08/2022, 9:18 PM/**
* Base.cfc
* @accessors true
*/
abstract component {
property string someProp;
function init() {
setSomeProp("default");
}
}
// AbstractIntermediary.cfc
import foo.*;
abstract component extends=Base {}
// SubImplementation.cfc
component extends=AbstractIntermediary {}
<cfscript>
// test.cfm
o = new SubImplementation()
writeDump(o.getSomeProp())
</cfscript>
And here's the final version --- I was actually setting accessors=true via the annotation syntax. And when you add abstract to that (because I guessed the wrong cause to error 1), then it stops generating accessors.Adam Cameron
abstract
combined with annotation-based accessors
is the issue?Tim
08/08/2022, 9:24 PMAdam Cameron
Adam Cameron
Adam Cameron
Tim
08/08/2022, 9:26 PMTim
08/08/2022, 9:31 PMTim
08/08/2022, 9:32 PMAdam Cameron
Adam Cameron
Tim
08/08/2022, 9:34 PMTim
08/08/2022, 9:39 PMseancorfield
Tim
08/08/2022, 9:55 PMseancorfield
@accessors
is valid in a comment?Tim
08/08/2022, 10:00 PMseancorfield
seancorfield
Adam Cameron
Tim
08/09/2022, 1:38 PMseancorfield
import
) shows how "dumb" the cfscript parser is 😞 The first one... well, I have no sympathy for anyone using annotations in comments 🤣