Skip to content

Commit

Permalink
Fix type compatibility on empty arrays (#4324)
Browse files Browse the repository at this point in the history
  • Loading branch information
aednichols authored Oct 30, 2018
1 parent de38c5e commit fdc6fdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

When the value `exit-code-timeout-seconds` is set, `check-alive` command is now only called once every timeout interval instead of each poll.

### Bug fixes

- Fixed a regression in Cromwell 36 that could cause operations on empty arrays to fail with a spurious type error (closes [#4318](https://github.com/broadinstitute/cromwell/issues/4318))

## 36 Release Notes

Expand Down
14 changes: 11 additions & 3 deletions wom/src/main/scala/wom/types/WomType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,17 @@ object WomType {
}

if (asArrayTypes.forall(_.isDefined)) {
val arrs = asArrayTypes.map(_.get)
val memberType = lowestCommonSubtype(arrs.map(_.memberType))
Some(WomArrayType(memberType))
val arrs = asArrayTypes.map(_.get)

/*
WomNothingType is not coercible to any other type, yet a empty array of type WomArrayType(WomNothingType) is
compatible with every other array type. Detect this here so we don't attempt primitive coercion on a type
that cannot be coerced.
Equivalent to logic found in typeSpecificIsCoerceableFrom on WomArrayType.
*/
val memberType = lowestCommonSubtype(arrs.map(_.memberType).filterNot(_.equals(WomNothingType)))
Some(WomArrayType(memberType))
} else None
}
}
Expand Down
5 changes: 4 additions & 1 deletion wom/src/test/scala/wom/types/WomTypeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ class WomTypeSpec extends FlatSpec with Matchers {
))
), WomObjectType),
(List(WomIntegerType, WomFloatType), WomFloatType),
(List(WomIntegerType, WomBooleanType), WomStringType)
(List(WomIntegerType, WomBooleanType), WomStringType),
(List(WomOptionalType(WomMaybeEmptyArrayType(WomSingleFileType)), WomMaybeEmptyArrayType(WomNothingType)), WomOptionalType(WomMaybeEmptyArrayType(WomSingleFileType))),
(List(WomMaybeEmptyArrayType(WomSingleFileType), WomMaybeEmptyArrayType(WomNothingType)), WomMaybeEmptyArrayType(WomSingleFileType)),
(List(WomMaybeEmptyArrayType(WomStringType), WomMaybeEmptyArrayType(WomIntegerType), WomMaybeEmptyArrayType(WomNothingType)), WomMaybeEmptyArrayType(WomStringType))
)

lcsTestCases foreach { case (types, expectedLcs) =>
Expand Down

0 comments on commit fdc6fdf

Please sign in to comment.