mirror of
https://github.com/apple/pkl.git
synced 2026-03-30 13:51:57 +02:00
Allow command options to have nullable types and default values (#1444)
This commit is contained in:
@@ -513,12 +513,6 @@ public final class CommandSpecParser {
|
||||
var typeNode = resolved.getFirst();
|
||||
isNullable = resolved.getSecond();
|
||||
defaultValue = CommandSpecParser.this.getDefaultValue(prop, requireExplicitDefault);
|
||||
if (isNullable && defaultValue != null) {
|
||||
throw exceptionBuilder()
|
||||
.evalError("commandOptionTypeNullableWithDefaultValue", prop.getName())
|
||||
.withSourceSection(prop.getHeaderSection())
|
||||
.build();
|
||||
}
|
||||
|
||||
resolve(prop, typeNode);
|
||||
return this;
|
||||
|
||||
@@ -1098,11 +1098,6 @@ Found both `@Flag` and `@Argument` annotations for options property `{0}`.\n\
|
||||
\n\
|
||||
Only one option type may be specified.
|
||||
|
||||
commandOptionTypeNullableWithDefaultValue=\
|
||||
Unexpected option property `{0}` with nullable type and default value.\n\
|
||||
\n\
|
||||
Options with default values must not be nullable.
|
||||
|
||||
commandOptionUnsupportedType=\
|
||||
Command option property `{0}` has unsupported {1}type `{2}`.
|
||||
|
||||
|
||||
@@ -292,26 +292,6 @@ class CommandSpecParserTest {
|
||||
assertThat(exc.message).contains("No type annotation found for `foo` property.")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nullable option with default not allowed`() {
|
||||
val moduleUri =
|
||||
writePklFile(
|
||||
"cmd.pkl",
|
||||
renderOptions +
|
||||
"""
|
||||
class Options {
|
||||
foo: String? = "bar"
|
||||
}
|
||||
"""
|
||||
.trimIndent(),
|
||||
)
|
||||
|
||||
val exc = assertThrows<PklException> { parse(moduleUri) }
|
||||
assertThat(exc.message).contains("foo: String? = \"bar\"")
|
||||
assertThat(exc.message)
|
||||
.contains("Unexpected option property `foo` with nullable type and default value")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `option with union type containing non-string-literals`() {
|
||||
val moduleUri =
|
||||
|
||||
Reference in New Issue
Block a user