Implicit casting in expressions

Implicit casting, or implicit conversion, is the act of Architect taking the implicit cast of one data type and converting the resulting value type to another data type. Architect only performs implicit conversions on the resulting value type of the valid expression text. Implicit casting takes advantage of certain features of type hierarchies or type representations. Architect performs implicit conversions when an expression of one type is used in context with a particular variable that does not accept that type.

In Architect, flow authors can only assign values of “like” types. A string variable can only have a string value assignment. But the Architect parser evaluates the data type of each expression and, if possible, reconciles the results for the flow author through an implicit cast.

In the following example, the flow author wants the integer to be expressed as a string. At runtime, the expression results in the string “5”.

ToString(5)

This is an example of an explicit cast where the expression author is converting the integer value 5 to a string by adding a ToString function call and passing in the integer. The resulting value of this expression when evaluated at runtime will be “5”.

A flow author could also enter the following valid string expression:

ToString(3+4)

This expression is considered an explicit cast. The flow author directed the parser to convert the integer to a string. Implicit cast happens only on the resulting type of expression text entered.

A flow author can also enter this valid string expression:

3+4

With regard to “like” types, this expression is invalid because the expression attempts to assign an integer to a string, but we know that a string variable can only have a string assignment. But with implicit casting, Architect can resolve the expression. The parser adds the ToString value around the expression, which converts the integer to a string, returning this expression:

ToString(3+4)

When Architect performs an implicit cast, it returns a message with conversion details on the expression’s Edit Expression dialog box.

Note: These conversion messages only appear in the Edit Expression dialog box. They do not appear in field-level literal or expression modes. However, Architect converts the expression whether you enter it at field level or in the Edit Expression dialog box.

Implicit casts are only performed on type cast functions that take one parameter. Type cast functions with multiple allowed parameters are not candidates for implicit conversion because the parser cannot process the action on any parameter  after the first one.

In the previous example, we knew the result would be an integer value of 7. But consider an example when we do not know what the value will be at design time:

Flow.MyInteger + 5

In this case, Flow.MyInteger is an integer data type. Conceptually, we know that the resulting value is “the value of Flow.MyInteger plus the value of 5″. We do not know what the value of Flow.MyInteger is, but we do know that it is an integer value plus another integer value, and this will result in an integer value. This is important for implicit casting: The result of integer + integer = integer, and the resulting type is a string.

When the parser evaluates the expression, it interprets that the resulting type is not a string but the result of the expression text is an integer. Therefore, it adds the ToString as an implicit cast and converts the result into a string which, is the desired result.

As in the previous example, when Architect performs an implicit cast, it returns a message with conversion details on the expression’s Edit Expression dialog box. These conversion messages only appear in the Edit Expression dialog box. They do not appear in field-level literal or expression modes. However, Architect converts the expression whether you enter it at field level or in the Edit Expression dialog box.

The parser only performs an implicit cast if the result is a valid expression. But let’s consider an example where the result is invalid. We know that, in the initial release, Architect only supports runtime data playback for three languages: en-US, fr-CA, and es-US. Therefore, the following expression works if the flow runs in en-US, fr-CA, or es-US:

ToAudioNumber(5005)

Architect can express the number 5005 any of the three languages. But what if a flow author adds Czech Republic (cs-CZ) as a supported language, which is not one of the 3 languages that includes runtime data playback support? The following examples illustrate how Architect handles invalid expressions.

When the flow author begins to type the integer, Architect immediately returns an error message:

If the flow author adds the ToAudioNumber function as an explicit cast, Architect still returns an error:

Data playback not supported