Skip to content

Simplify conflict shape loading conflict handling #514

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

Merged
merged 1 commit into from
Jul 29, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -238,30 +238,27 @@ private void onTraitDefinition(ShapeId target, TraitDefinition definition) {
private boolean validateOnShape(ShapeId id, FromSourceLocation source) {
if (!hasDefinedShape(id)) {
return true;
} else if (Prelude.isPreludeShape(id)) {
// Ignore prelude shape conflicts since it's such a common case of
// passing an already built model into a ModelAssembler.
return false;
}

// Ignore prelude shape conflicts since it's such a common case of
// passing an already built model into a ModelAssembler.
if (!Prelude.isPreludeShape(id)) {
// The shape has been duplicated, so get the previously defined pending shape or built shape.
SourceLocation previous = Optional.<FromSourceLocation>ofNullable(pendingShapes.get(id))
.orElseGet(() -> builtShapes.get(id)).getSourceLocation();
// Cannot ignore duplicate member definitions.
boolean canIgnore = !id.getMember().isPresent()
// Ignore duplicate shapes defined in the same file.
&& previous != SourceLocation.NONE
&& previous.equals(source.getSourceLocation());
if (canIgnore) {
LOGGER.warning(() -> "Ignoring duplicate shape definition defined in the same file: "
+ id + " defined at " + source.getSourceLocation());
} else {
String message = String.format("Duplicate shape definition for `%s` found at `%s` and `%s`",
id, previous.getSourceLocation(), source.getSourceLocation());
throw new SourceException(message, source);
}
}
// The shape has been duplicated, so get the previously defined pending shape or built shape.
SourceLocation previous = Optional.<FromSourceLocation>ofNullable(pendingShapes.get(id))
.orElseGet(() -> builtShapes.get(id)).getSourceLocation();

return false;
// Ignore duplicate shapes defined in the same file (this can happen
// when the same file is included multiple times in a model assembler).
if (previous != SourceLocation.NONE && previous.equals(source.getSourceLocation())) {
LOGGER.warning(() -> "Ignoring duplicate shape definition defined in the same file: "
+ id + " defined at " + source.getSourceLocation());
return false;
} else {
String message = String.format("Duplicate shape definition for `%s` found at `%s` and `%s`",
id, previous.getSourceLocation(), source.getSourceLocation());
throw new SourceException(message, source);
}
}

/**
Expand Down