Skip to content

Commit e00702c

Browse files
fourlscirras
authored andcommitted
Downgrade duplicate unit import error to warning
1 parent 6ac3f1a commit e00702c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- The `Copy` intrinsic inferred an incorrect return type for `PChar`, `PAnsiChar`, and variants.
1313
- The `Concat` intrinsic inferred an incorrect return type for single-character string literals.
1414
- Ideographic space (U+3000) was erroneously accepted as a valid identifier character.
15+
- Duplicate imports in a `requires` clause now log a warning instead of throwing an exception.
1516

1617
## [1.1.0] - 2024-01-02
1718

delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/scope/FileScopeImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.Map;
3333
import java.util.Set;
3434
import java.util.stream.Collectors;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3537
import org.sonar.plugins.communitydelphi.api.ast.ArrayAccessorNode;
3638
import org.sonar.plugins.communitydelphi.api.ast.NameDeclarationNode;
3739
import org.sonar.plugins.communitydelphi.api.ast.NameReferenceNode;
@@ -48,6 +50,7 @@
4850
import org.sonar.plugins.communitydelphi.api.type.Type.HelperType;
4951

5052
public abstract class FileScopeImpl extends DelphiScopeImpl implements FileScope {
53+
private static final Logger LOG = LoggerFactory.getLogger(FileScopeImpl.class);
5154
private final String name;
5255
private final Deque<FileScope> imports = new ArrayDeque<>();
5356
private Map<Integer, DelphiScope> registeredScopes = new HashMap<>();
@@ -107,7 +110,17 @@ public void addDeclaration(NameDeclaration declaration) {
107110
imports.addFirst(scope);
108111
}
109112
}
110-
super.addDeclaration(declaration);
113+
114+
try {
115+
super.addDeclaration(declaration);
116+
} catch (DuplicatedDeclarationException e) {
117+
if (declaration instanceof UnitImportNameDeclaration) {
118+
// 'requires' clauses can have multiple occurrences of the same unit import
119+
LOG.warn("Duplicate unit import found: {}", e.getMessage());
120+
} else {
121+
throw e;
122+
}
123+
}
111124
}
112125

113126
@Override

0 commit comments

Comments
 (0)