Hi guys
I'm getting errors with the Royale compiler when trying to access the
properties of a Date object ("Error: Access of possibly undefined property
fullYear through a reference with static type Date.")
Having looked into it, this is because the JavaScript 'Date' object has
"getFullYear" and "setFullYear", rather than set/get functions. There looks
like there's some clever code going on within BinaryOperatorEmitter.java which
should be able to handle this and translate the output (which it does, and
which works fine), but we're getting the AccessUndefinedMemberProblem error
reported prior to this.
It looked to me as if there were a few possible workarounds for this, but I was
thinking it might be better if someone a little more familiar with the compiler
code was to look at this? I put in a hack within the
"MethodBodySemanticChecker" class, in the "checkMemberAccess" method:
IDefinition def = utils.getDefinition(member_node);
// Is this a special case of "Date" where access to properties need to
be functions?
if ( (def == null) && (iNode instanceof MemberAccessExpressionNode) )
{
IExpressionNode left = ((MemberAccessExpressionNode)
iNode).getLeftOperandNode();
IExpressionNode right = ((MemberAccessExpressionNode)
iNode).getRightOperandNode();
if (left instanceof IdentifierNode && right instanceof
IdentifierNode)
{
ITypeDefinition classLeft = left.resolveType(project);
if (classLeft != null &&
classLeft.getBaseName().equals("Date") )
{
// is the right hand side one of our acceptable
elements?
String memberName = ((IdentifierNode) right).getName();
final String[] allowed = { "time", "fullYear", "month",
"date", "fullYearUTC",
"monthUTC",
"dateUTC", "hours", "minutes", "seconds",
"milliseconds",
"hoursUTC", "minutesUTC",
"secondsUTC","millisecondsUTF" };
if ( Arrays.asList(allowed).contains(memberName) )
return;
}
}
}
if ( def == null && utils.definitionCanBeAnalyzed(member) )
{
This works - and the other BinaryOperatorEmitter code then kicks in to output
the correct JavaScript - but it's not very elegant! and may screw up if anyone
has created their own something.Date class .. so I was thinking it would be
better to be fixed by an expert!
Let me know if you'd like me to raise an issue on the royale-compiler github
project for this..
thanks
Andrew