Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for duplicate record type field names #10

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ We support [Dhall 15.0.0][dhall-15], including the `with` keyword and record pun

We're running the [Dhall acceptance test suites][dhall-tests] for parsing, normalization,
[CBOR][cbor] encoding and decoding, hashing, and type inference (everything except imports), and
currently 1,139 of 1,143 tests are passing. There are three open issues that track the acceptance
currently 1,140 of 1,143 tests are passing. There are two open issues that track the acceptance
tests that are not passing or that we're not running yet:
[#5](https://github.com/travisbrown/dhallj/issues/5),
[#6](https://github.com/travisbrown/dhallj/issues/6), and
[#5](https://github.com/travisbrown/dhallj/issues/5) and
[#8](https://github.com/travisbrown/dhallj/issues/8).

There are several known issues:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,24 @@ public final Expr onRecord(Iterable<Entry<String, Expr>> fields, int size) {
}

public final Expr onRecordType(Iterable<Entry<String, Expr>> fields, int size) {
// Need to check for duplicates here; see: https://github.com/travisbrown/dhallj/issues/6
Set<String> fieldNamesSeen = new HashSet<>(size);

Universe max = Universe.TYPE;

for (Entry<String, Expr> field : fields) {
String fieldName = field.getKey();

if (!fieldNamesSeen.add(fieldName)) {
throw TypeCheckFailure.makeFieldDuplicateError(fieldName);
}

Universe universe = Universe.fromExpr(field.getValue().accept(this));

if (universe != null) {
max = max.max(universe);
} else {
throw TypeCheckFailure.makeFieldTypeError(field.getKey());
throw TypeCheckFailure.makeFieldTypeError(fieldName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ static TypeCheckFailure makeFieldTypeError(String fieldName) {
return new TypeCheckFailure("Invalid field type");
}

static TypeCheckFailure makeFieldDuplicateError(String fieldName) {
return new TypeCheckFailure(String.format("duplicate field: %s", fieldName));
}

static TypeCheckFailure makeListTypeMismatchError(Expr type1, Expr type2) {
return new TypeCheckFailure("List elements should all have the same type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class TypeCheckingOtherSuite extends TypeCheckingSuite("type-inference/success")
override def ignored = Set("CacheImports", "CacheImportsCanonicalize")
override def slow = Set("prelude")
}
class TypeCheckingFailureUnitSuite extends TypeCheckingFailureSuite("type-inference/failure/unit") {
// The spec says we shouldn't have to worry about duplicate fields during type checking.
override def ignored = Set("RecordTypeDuplicateField")
}
class TypeCheckingFailureUnitSuite extends TypeCheckingFailureSuite("type-inference/failure/unit")

class ParsingUnitSuite extends ParsingSuite("parser/success/unit") {
override def ignored = Set("SomeXYZ")
Expand Down