Skip to content

Commit

Permalink
Merge aa11870 into c337ac7
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Sep 12, 2022
2 parents c337ac7 + aa11870 commit 01bc49b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion WDL/StdLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def infer_type(self, expr: "Expr.Apply") -> Type.Base:
if t2 is None:
# neither operand is a string; defer to _ArithmeticOperator
return super().infer_type(expr)
if not t2.coerces(Type.String(optional=not expr._check_quant)):
if not t2.coerces(Type.String(), check_quant=expr._check_quant):
raise Error.IncompatibleOperand(
expr,
"Cannot add/concatenate {} and {}".format(
Expand Down
14 changes: 8 additions & 6 deletions WDL/Type.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(self, optional: bool = False) -> None:
def check(self, rhs: Base, check_quant: bool = True) -> None:
""""""
if isinstance(rhs, String):
return
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)


Expand All @@ -162,7 +162,7 @@ def __init__(self, optional: bool = False) -> None:
def check(self, rhs: Base, check_quant: bool = True) -> None:
""""""
if isinstance(rhs, String):
return
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)


Expand All @@ -175,7 +175,7 @@ def check(self, rhs: Base, check_quant: bool = True) -> None:
if isinstance(rhs, Float):
return self._check_optional(rhs, check_quant)
if isinstance(rhs, String):
return
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)


Expand All @@ -186,7 +186,7 @@ def __init__(self, optional: bool = False) -> None:
def check(self, rhs: Base, check_quant: bool = True) -> None:
""""""
if isinstance(rhs, String):
return
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)


Expand All @@ -197,7 +197,7 @@ def __init__(self, optional: bool = False) -> None:
def check(self, rhs: Base, check_quant: bool = True) -> None:
""""""
if isinstance(rhs, String):
return
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)


Expand Down Expand Up @@ -261,7 +261,9 @@ def check(self, rhs: Base, check_quant: bool = True) -> None:
self.item_type.check(rhs.item_type, check_quant)
return self._check_optional(rhs, check_quant)
if isinstance(rhs, String):
return None if self.item_type is None else self.item_type.check(String())
if self.item_type is not None:
self.item_type.check(String())
return self._check_optional(rhs, check_quant)
super().check(rhs, check_quant)

def copy(self, optional: Optional[bool] = None, nonempty: Optional[bool] = None) -> Base:
Expand Down
12 changes: 7 additions & 5 deletions tests/test_3corpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class Contrived(unittest.TestCase):
"NameCollision": 43,
"StringCoercion": 11,
"FileCoercion": 5,
"OptionalCoercion": 3,
"OptionalCoercion": 4,
"NonemptyCoercion": 2,
"UnnecessaryQuantifier": 9,
"UnusedDeclaration": 9,
Expand All @@ -451,14 +451,16 @@ class Contrived2(unittest.TestCase):
# these use the pattern 'input { Type? x = default }' and need check_quant=False
"mergecounts",
"somaticseq",
"bamstats",
"biopet",
"sampleconfig",
"seqstat",
],
expected_lint={
"OptionalCoercion": 9,
"UnusedDeclaration": 18,
"OptionalCoercion": 2,
"UnusedDeclaration": 15,
"NonemptyCoercion": 1,
"NameCollision": 1,
"SelectArray": 1,
"UnverifiedStruct": 1,
"UnnecessaryQuantifier": 8,
},
)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_7runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,34 @@ def test_spec_select_all_wdl(self):
self.assertEqual(outp["fivethree"], [5, 3])
self.assertEqual(outp["is_true"], True)

def test_issue596(self):
self._run("""
task reference_prepare {
input {
# You need to define either this...
File? reference_fa_file
# Or both of these.
File? reference_zipped_directory
String? reference_fa_filename_in_zipped_directory
}
# get the basename of the reference
String? basename_reference = basename(reference_zipped_directory)
command <<<
set -eux -o pipefail
if [[ ! "~{reference_zipped_directory}" = "" ]]
then
cp ~{reference_zipped_directory} .
unzip ~{basename_reference}
fi
# do other things here
>>>
}""", {}, expected_exception=WDL.Error.StaticTypeMismatch)

class TestInlineDockerfile(RunnerTestCase):
@log_capture()
def test1(self, capture):
Expand Down

0 comments on commit 01bc49b

Please sign in to comment.