Skip to content

Commit

Permalink
feat: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Oct 22, 2023
1 parent becfb2a commit 07239f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/language/validation/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,14 @@ export const moduleMemberMustHaveNameThatIsUniqueInPackage = (services: SafeDsSe
const packageName = getPackageName(member) ?? '';

let declarationsInPackage: AstNodeDescription[];
let kind: string;
if (packageName.startsWith(BUILTINS_ROOT_PACKAGE)) {
// For a builtin package the simple names of declarations must be unique
declarationsInPackage = packageManager.getDeclarationsInPackageOrSubpackage(BUILTINS_ROOT_PACKAGE);
kind = 'builtin declarations';
} else {
declarationsInPackage = packageManager.getDeclarationsInPackage(packageName);
kind = 'declarations in this package';
}

if (
Expand All @@ -248,7 +251,7 @@ export const moduleMemberMustHaveNameThatIsUniqueInPackage = (services: SafeDsSe
!builtinUris.has(it.documentUri.toString()),
)
) {
accept('error', `Multiple declarations in this package have the name '${member.name}'.`, {
accept('error', `Multiple ${kind} have the name '${member.name}'.`, {
node: member,
property: 'name',
code: CODE_NAME_DUPLICATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ package safeds.lang
// $TEST$ no error r"Multiple declarations in this package have the name '\w*'\."
class »Any«

// $TEST$ error "Multiple declarations in this package have the name 'DuplicateAnnotation'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateAnnotation'."
annotation »DuplicateAnnotation«
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateClass'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateClass'."
class »DuplicateClass«
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateEnum'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateEnum'."
enum »DuplicateEnum«
// $TEST$ error "Multiple declarations in this package have the name 'duplicateFunction'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicateFunction'."
fun »duplicateFunction«()
// $TEST$ no error r"Multiple declarations in this package have the name '\w*'\."
// $TEST$ no error r"Multiple builtin declarations have the name '\w*'\."
pipeline »duplicatePipeline« {}
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateSchema'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateSchema'."
schema »DuplicateSchema« {}
// $TEST$ error "Multiple declarations in this package have the name 'duplicatePublicSegment'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicatePublicSegment'."
segment »duplicatePublicSegment«() {}
// $TEST$ error "Multiple declarations in this package have the name 'duplicateInternalSegment'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicateInternalSegment'."
internal segment »duplicateInternalSegment«() {}
// $TEST$ no error r"Multiple declarations in this package have the name '\w*'\."
// $TEST$ no error r"Multiple builtin declarations have the name '\w*'\."
private segment »duplicatePrivateSegment«() {}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package safeds.lang.other

// $TEST$ error "Multiple declarations in this package have the name 'DuplicateAnnotation'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateAnnotation'."
annotation »DuplicateAnnotation«
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateClass'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateClass'."
class »DuplicateClass«
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateEnum'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateEnum'."
enum »DuplicateEnum«
// $TEST$ error "Multiple declarations in this package have the name 'duplicateFunction'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicateFunction'."
fun »duplicateFunction«()
// $TEST$ no error r"Multiple declarations in this package have the name '\w*'\."
// $TEST$ no error r"Multiple builtin declarations have the name '\w*'\."
pipeline »duplicatePipeline« {}
// $TEST$ error "Multiple declarations in this package have the name 'DuplicateSchema'."
// $TEST$ error "Multiple builtin declarations have the name 'DuplicateSchema'."
schema »DuplicateSchema« {}
// $TEST$ error "Multiple declarations in this package have the name 'duplicatePublicSegment'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicatePublicSegment'."
segment »duplicatePublicSegment«() {}
// $TEST$ error "Multiple declarations in this package have the name 'duplicateInternalSegment'."
// $TEST$ error "Multiple builtin declarations have the name 'duplicateInternalSegment'."
internal segment »duplicateInternalSegment«() {}
// $TEST$ no error r"Multiple declarations in this package have the name '\w*'\."
// $TEST$ no error r"Multiple builtin declarations have the name '\w*'\."
private segment »duplicatePrivateSegment«() {}

0 comments on commit 07239f8

Please sign in to comment.