Issue Details (XML | Word | Printable)

Key: FDT-1269
Type: Bug Bug
Status: Closed Closed
Priority: Minor Minor
Assignee: FDT Team
Reporter: Martin Heidegger
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
FDT

Annonymous Objects don't have Object methods

Created: 15/Sep/10 07:59 AM   Updated: 13/May/13 02:26 PM
Component/s: Autocompletion, Editor (Deprecated)
Affects Version/s: FDT 4 RC 1
Fix Version/s: FDT
Security Level: public

Time Tracking:
Not Specified

Issue Links:
Duplicate
 

Review Type: Review by Product Owner


 Description  « Hide
Accessing a non-typed variable like:
object["somechild"].toString();

or

var obj: *;
obj.toString();

doesn't offer code completion at all even though all variables in ActionScript3 are objects and therefore contain the Object methods.
Even worse, former mentioned .toString calls would show a warning even though they are perfectly legal.

Sideeffect from this problem: If some custom class doesn't implement toString, toString is also not shown in code completion.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Nico Zimmermann added a comment - 15/Sep/10 09:16 AM
Hi Martin,

I am not sure if what you suggest is right. Please review this example:

package
{
	import flash.display.Sprite;

	public class ToStringTest extends Sprite
	{
		public function ToStringTest()
		{
			var o : Object;
			o.toString = 1; //is correct and compiles well
			
			toString = 1; // is wrong, will not compile
		}
		
		override public function toString() : String
		{
			return super.toString();
		}
	}
}

So... class Object does not contain the method "toString" (not as in Java). You can add "toString" as an "int" to a dynamic object. However, if FDT would bind "toString" to a dynamic object, then it would cause an error at "o.toString = 1". So, from a semantic point of view, the FDT behavoir is right.

FDT could add "toString() : String" to autocompletion, but I think it's not correct to give proposals that are in fact not right.

Any thoughts on this?

Greets, Nico.


Nico Zimmermann added a comment - 15/Sep/10 09:19 AM
package
{

	public class XXX
	{
		override public function toString() : String {
			return "XXX";
		}
	}
}

The code above will also not compile. So the compiler is very clear about this, however the Flash VM, interpretes toString on serveral occasions. But that's a different story...


Martin Heidegger added a comment - 15/Sep/10 09:58 AM
The way it works consistent looks to me like this:

1) Dynamic classes like {} have the "toString" property ALWAYS assigned. If not overwritten (like in your example) it contains a function. So the chances are quite high toString contains a function in dynamic objects. It will be the case usually. If toString is certainly defined then toString is for sure. Never the less I think a .toString code-completion has a 99.9% chance of being useful.

2) Normal classes that don't have a toString property/method defined do have the Object's toString method.

That concludes to me:
With normal classes its clear: toString exists and if not defined differently its a function without parameters.
With dynamic classes the method exists and I would offer code completion to a method but I would show a warning stating that accessing these methods might conflict with different use and I would make a switch in the FDT Problems dialog.

And not to forget: the other methods are not really less important


Nico Zimmermann added a comment - 15/Sep/10 09:19 PM
ok - I tried this:
var foo : EmptyClass = new EmptyClass();
trace (foo["toString"]); // returns function
trace (foo.toString); // does not compile
			
var a : Object = {};
trace (a.toString); // return function

So... at runtime "toString" always exists. But it will only compile:

  • with typed objects instanciated from a "dynamic" class
  • if the type cannot be resolved (array access, star type, no type) - as you wrote in the first place.

Only on those occasions FDT should propose "toString". So "toString" cannot be added to Object (because of inheritance), but to "dynamic or untyped objects".

You are right - it makes sense to add a special problem for that in order to switch it off - maybe that can be default.
Problem Text could be: "Method toString() might conflict with different use in this object".

Thank you for clarifying that!

Greets, Nico.


Panel added a comment - 06/May/11 12:33 PM

FDT Team added a comment - 13/May/13 02:26 PM
Fixed for next release: 13. May