diff --git a/src/language/validation/names.ts b/src/language/validation/names.ts index 503671100..1b5b98fb5 100644 --- a/src/language/validation/names.ts +++ b/src/language/validation/names.ts @@ -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 ( @@ -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, diff --git a/tests/resources/validation/names/duplicates/across files/safeds 1.sdstest b/tests/resources/validation/names/duplicates/across files/safeds 1.sdstest index 6b377dbb1..605fa9d5e 100644 --- a/tests/resources/validation/names/duplicates/across files/safeds 1.sdstest +++ b/tests/resources/validation/names/duplicates/across files/safeds 1.sdstest @@ -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«() {} diff --git a/tests/resources/validation/names/duplicates/across files/safeds 2.sdstest b/tests/resources/validation/names/duplicates/across files/safeds 2.sdstest index 5bf01fb1b..c0f4a34d0 100644 --- a/tests/resources/validation/names/duplicates/across files/safeds 2.sdstest +++ b/tests/resources/validation/names/duplicates/across files/safeds 2.sdstest @@ -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«() {}