You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the type system expects a certain concept, we should not use the colon cast (:) to cast nodes to a different type but rather use the as cast. This cast returns null if the cast is not successful, for example when a user provides a node of a wrong type or the RuntimeErrorType is returned. I've fixed a few of such issues in the past but there are so many hidden cases, it's probably better to just ban this cast and replace all instances in the type system.
Example exception:
jetbrains.mps.lang.smodel.generator.smodelAdapter.NodeCastException: Can't cast node: 5190981625519587906, concept: org.iets3.core.expr.simpleTypes.structure.NumberType to concept: org.iets3.core.expr.collections.structure.CollectionType
at jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.cast(SNodeOperations.java:559)
at org.iets3.core.expr.collections.typesystem.typeof_AsListOp_InferenceRule$1.run(typeof_AsListOp_InferenceRule.java:28)
The text was updated successfully, but these errors were encountered:
I am not sure whether replacing colon casts with as is a sufficient solution to these kind of errors.
To me they are more of a symptom than an actual problem:
If I see a NodeCastException for a RuntimeErrorType in the type system, this means that the typesystem code does not encode enough information about negative cases, i.e. the rule in question is not robust against errors in the underlying expressions.
In the long run, replacing a colon cast with as might even cause more problems, because now the type system code will also have to be handle the cases where the cast fails.
I see two alternative solutions here:
Follow the approach of a strongly-typed language and treat RuntimeErrorType as an error. Hence if any argument type is RuntimeErrorType the overall type should also become RuntimeErrorType
Make RuntimeErrorType a sub-type of all KernelF types and silently allow the type system to continue type checking in a "best effort" manner.
Personally, I would favor the first solution, but this is up to discussion.
When the type system expects a certain concept, we should not use the colon cast (:) to cast nodes to a different type but rather use the
as
cast. This cast returns null if the cast is not successful, for example when a user provides a node of a wrong type or theRuntimeErrorType
is returned. I've fixed a few of such issues in the past but there are so many hidden cases, it's probably better to just ban this cast and replace all instances in the type system.Example exception:
The text was updated successfully, but these errors were encountered: