Fix cast and instanceof with record types#7185
Conversation
✅ Deploy Preview for nextflow-docs-staging canceled.
|
|
In my opinion, this behaviour is strange or at least incomplete; a user could do something like this: You create a record, cast it to |
|
Good catch. I actually meant to implement a compiler transform for that as well, so that I will try to implement that in this PR |
|
@jorgee added the runtime check for |
Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Ben Sherman <[email protected]>
2467cd2 to
998d11e
Compare
Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Ben Sherman <[email protected]>
|
The new cast that redirects to |
Signed-off-by: Ben Sherman <[email protected]>
|
Good catches. I was wondering about this too, whether to override all cast expressions or not. I updated the cast visitor to preserve the existing behavior and only inject the runtime check for things like |
|
I think the check of the existing |
|
Some users have asked to make Instead, I introduced a new default with the The Since this PR is meant to be a bug fix for 26.04, I restricted the changes to only affect new use cases (parameterized types and record types). But we should probably also apply this behavior to |
This PR fixes the use of casting records to a named record type, for example:
workflow { record(id: '1', fastq: file('1.fastq')) as Sample } record Sample { id: String fastq: Path }Casting a record to a named record type should be a no-op at runtime. It is only used by the type checker to validate that the record satisfies the requirements of the record type.
If the cast is is not removed at runtime, the record would be cast to an instance of
Sample, since record types are compiled to actual classes at runtime with an implicit constructor. This would break the runtime's assumption that all records areRecordMaps.