Skip to content

Commit

Permalink
fix: don't show an info when editing the builtin files
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Nov 11, 2023
1 parent cf2db81 commit ae47bc1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/safe-ds-lang/src/language/helpers/nodeProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ export const getParentTypes = (node: SdsClass | undefined): SdsType[] => {
return node?.parentTypeList?.parentTypes ?? [];
};

export const getQualifiedName = (node: SdsDeclaration | undefined): string | undefined => {
const segments = [];

let current: SdsDeclaration | undefined = node;
while (current) {
if (current.name) {
segments.unshift(current.name);
}
current = getContainerOfType(current.$container, isSdsDeclaration);
}

return segments.join('.');
};

export const streamPlaceholders = (node: SdsBlock | undefined): Stream<SdsPlaceholder> => {
return stream(getStatements(node)).filter(isSdsAssignment).flatMap(getAssignees).filter(isSdsPlaceholder);
};
Expand Down
16 changes: 13 additions & 3 deletions packages/safe-ds-lang/src/language/validation/inheritance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expandToStringWithNL, ValidationAcceptor } from 'langium';
import { expandToStringWithNL, getContainerOfType, ValidationAcceptor } from 'langium';
import { isEmpty } from '../../helpers/collectionUtils.js';
import { SdsClass, type SdsClassMember } from '../generated/ast.js';
import { getParentTypes } from '../helpers/nodeProperties.js';
import { isSdsClass, SdsClass, type SdsClassMember } from '../generated/ast.js';
import { getParentTypes, getQualifiedName } from '../helpers/nodeProperties.js';
import { SafeDsServices } from '../safe-ds-module.js';
import { ClassType, UnknownType } from '../typing/model.js';

Expand Down Expand Up @@ -40,6 +40,11 @@ export const classMemberMustMatchOverriddenMemberAndShouldBeNeeded = (services:
},
);
} else if (typeChecker.isAssignableTo(overriddenMemberType, ownMemberType)) {
// Prevents the info from showing when editing the builtin files
if (isInSafedsLangAnyClass(node)) {
return;
}

accept('info', 'Overriding member is identical to overridden member and can be removed.', {
node,
property: 'name',
Expand All @@ -49,6 +54,11 @@ export const classMemberMustMatchOverriddenMemberAndShouldBeNeeded = (services:
};
};

const isInSafedsLangAnyClass = (node: SdsClassMember): boolean => {
const containingClass = getContainerOfType(node, isSdsClass);
return isSdsClass(containingClass) && getQualifiedName(containingClass) === 'safeds.lang.Any';
};

export const classMustOnlyInheritASingleClass = (services: SafeDsServices) => {
const typeComputer = services.types.TypeComputer;
const computeType = typeComputer.computeType.bind(typeComputer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package safeds.lang

class Any {
// $TEST$ no info "Overriding member is identical to overridden member and can be removed."
fun »toString«() -> s: String
}

0 comments on commit ae47bc1

Please sign in to comment.