Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
Last time I gave some vague, high-level definitions of the type system concepts promotable, assignable and coercible. Today I'll give a more precise definition of promotable. The others I'll define more precisely later.
Suppose we have an assignment of an expression to a typed field.
Left Hand Side Expression = Right Hand Side Expression;
where the compiler can infer the type of the left hand side as LHT and the right hand side as RHT. RHT is promotable to LHT if every member of RHT is coercible to LHT.
There are, as you'll see, some bugs and weirdnesses in JScript .NET's implementation of the promotability algorithm. This describes how it is, not how it should be!
In this list of rules there are some contradictions -- in those cases, earlier rules supercede later rules.
Rules for the case where LHT is an array type
Rules for the case where LHT or RHT is an enumerated type
Note that the rules for enumerated types are exceptions; clearly there are always strings and numbers which are not coercible to a given enumerated type!
Rules for the case where RHT or LHT is a class/interface
Rules for the case where RHT and LHT are both primitive types
Next time, assignability.
A JScript array is NOT a System.Array object, so you can't use it as one. In a JScript.NET program you can coerce between JScript arrays and system arrays, but that's a copy-on-cast relationship, not an "is a" relationship.
However, in your C# program, you CAN cast the object to public class Microsoft.Jscript.ArrayObject, which DOES have an indexer. That should solve your problem.