Skip to content

Commit f3cf63b

Browse files
committed
Handle null/unit constant types.
Previously, the snapshot-lsif command failed when encountering these types.
1 parent 2f0bc22 commit f3cf63b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/SignatureFormatter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ private String formatTree(Tree tree) {
472472
}
473473

474474
private String formatConstant(Constant constant) {
475-
if (constant.hasBooleanConstant()) {
475+
if (constant.hasUnitConstant()) {
476+
return isScala ? "()" : "scala.Unit()";
477+
} else if (constant.hasBooleanConstant()) {
476478
return Boolean.toString(constant.getBooleanConstant().getValue());
477479
} else if (constant.hasByteConstant()) {
478480
return Integer.toString(constant.getByteConstant().getValue());
@@ -490,6 +492,8 @@ private String formatConstant(Constant constant) {
490492
return Double.toString(constant.getDoubleConstant().getValue());
491493
} else if (constant.hasStringConstant()) {
492494
return '"' + constant.getStringConstant().getValue() + '"';
495+
} else if (constant.hasNullConstant()) {
496+
return "null";
493497
}
494498
throw new IllegalArgumentException("constant was not of known type " + constant);
495499
}

semanticdb-java/src/main/protobuf/semanticdb.proto

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ enum BinaryOperator {
346346

347347
message Constant {
348348
oneof sealed_value {
349+
UnitConstant unit_constant = 1;
349350
BooleanConstant boolean_constant = 2;
350351
ByteConstant byte_constant = 3;
351352
ShortConstant short_constant = 4;
@@ -355,9 +356,13 @@ message Constant {
355356
FloatConstant float_constant = 8;
356357
DoubleConstant double_constant = 9;
357358
StringConstant string_constant = 10;
359+
NullConstant null_constant = 11;
358360
}
359361
}
360362

363+
message UnitConstant {
364+
}
365+
361366
message BooleanConstant {
362367
bool value = 1;
363368
}
@@ -392,4 +397,7 @@ message DoubleConstant {
392397

393398
message StringConstant {
394399
string value = 1;
395-
}
400+
}
401+
402+
message NullConstant {
403+
}

0 commit comments

Comments
 (0)