method(:testMethod) gives an error in certain contexts. Used to work fine on ConnectIQ 2.2.6
The Environment:
- OS X and Windows
- Eclipse Neon.2 (4.6.2) and Mars (4.5.2)
- ConnectIQ 2.3.1
A detailed description of the issue
- A function testMethod() is created out of a class and without explicitly defining a module.
- It can be called from inside a class and from other functions at the same level
- It can also be called from inside a class using method(:testMethod).invoke()
- It can also be called from other functions at the same level if method(:testMethod) is passed as a parameter and then .invoke() is called on this parameter.
- But if you use method(:testMethod) in a function on that same level, you get a runtime error: "Could not find symbol method"
It worked fine on ConnectIQ 2.2.6, both on simulator and real devices. Is it a bug or not allowed anymore?
Steps to reproduce the issue
using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
class TestFooView extends Ui.View {
function onUpdate(dc) {
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
Sys.println("Calling testMethod() from TestFooView class.");
testMethod();
Sys.println("Calling method(:testMethod).invoke() from TestFooView class.");
method(:testMethod).invoke();
Sys.println("Calling callTestMethodFromTheSameLevel() from TestFooView class.");
callTestMethodFromTheSameLevel();
Sys.println("Calling receiveMethodObjAndInvoke(method(:testMethod)) from TestFooView class.");
receiveMethodObjAndInvoke(method(:testMethod));
Sys.println("Calling createMethodObjAndInvoke() from TestFooView class.");
createMethodObjAndInvoke();
}
function onHide() {}
function initialize() {View.initialize();}
function onLayout(dc) {setLayout(Rez.Layouts.MainLayout(dc));}
function onShow() {}
}
function callTestMethodFromTheSameLevel(){
Sys.println(" callTestMethodFromTheSameLevel() calls testMethod()");
testMethod();
}
function receiveMethodObjAndInvoke(aMethod){
Sys.println(" receiveMethodObjAndInvoke(aMethod) calls aMethod.invoke()");
aMethod.invoke();
}
function createMethodObjAndInvoke(){
Sys.println(" createMethodObjAndInvoke() calls method(:testMethod).invoke()");
method(:testMethod).invoke(); // <------------------------------------------ HERE IS THE PROBLEM!
}
function testMethod(){
Sys.println("-> OK! testMethod() responded.");
}
Output CIQ 2.3.1:
Calling testMethod() from TestFooView class.
-> OK! testMethod() responded.
Calling method(:testMethod).invoke() from TestFooView class.
-> OK! testMethod() responded.
Calling callTestMethodFromTheSameLevel() from TestFooView class.
callTestMethodFromTheSameLevel() calls testMethod()
-> OK! testMethod() responded.
Calling receiveMethodObjAndInvoke(method(:testMethod)) from TestFooView class.
receiveMethodObjAndInvoke(aMethod) calls aMethod.invoke()
-> OK! testMethod() responded.
Calling createMethodObjAndInvoke() from TestFooView class.
createMethodObjAndInvoke() calls method(:testMethod).invoke()
Could not find symbol method.Failed invoking <symbol>Symbol Not Found Error
in createMethodObjAndInvoke (C:\Users\rrezende\workspace\TestFoo\source\TestFooView.mc:44)
in onUpdate (C:\Users\rrezende\workspace\TestFoo\source\TestFooView.mc:23)
Output CIQ 2.2.6:
Calling testMethod() from TestFooView class.
-> OK! testMethod() responded.
Calling method(:testMethod).invoke() from TestFooView class.
-> OK! testMethod() responded.
Calling callTestMethodFromTheSameLevel() from TestFooView class.
callTestMethodFromTheSameLevel() calls testMethod()
-> OK! testMethod() responded.
Calling receiveMethodObjAndInvoke(method(:testMethod)) from TestFooView class.
receiveMethodObjAndInvoke(aMethod) calls aMethod.invoke()
-> OK! testMethod() responded.
Calling createMethodObjAndInvoke() from TestFooView class.
createMethodObjAndInvoke() calls method(:testMethod).invoke()
-> OK! testMethod() responded.