-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eeda845
commit bdb0a5a
Showing
2 changed files
with
21 additions
and
21 deletions.
There are no files selected for viewing
38 changes: 19 additions & 19 deletions
38
src/language/validation/other/expressions/memberAccesses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import {SafeDsServices} from "../../../safe-ds-module.js"; | ||
import {SdsMemberAccess} from "../../../generated/ast.js"; | ||
import {ValidationAcceptor} from "langium"; | ||
import {UnknownType} from "../../../typing/model.js"; | ||
import { SafeDsServices } from '../../../safe-ds-module.js'; | ||
import { SdsMemberAccess } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { UnknownType } from '../../../typing/model.js'; | ||
|
||
export const CODE_MEMBER_ACCESS_MISSING_NULL_SAFETY = 'member-access/missing-null-safety'; | ||
|
||
export const memberAccessMustBeNullSafeIfReceiverIsNullable = | ||
(services: SafeDsServices) => | ||
(node: SdsMemberAccess, accept: ValidationAcceptor): void => { | ||
if (node.isNullSafe) { | ||
return; | ||
} | ||
(node: SdsMemberAccess, accept: ValidationAcceptor): void => { | ||
if (node.isNullSafe) { | ||
return; | ||
} | ||
|
||
const receiverType = services.types.TypeComputer.computeType(node.receiver); | ||
if (receiverType === UnknownType) { | ||
return; | ||
} | ||
const receiverType = services.types.TypeComputer.computeType(node.receiver); | ||
if (receiverType === UnknownType) { | ||
return; | ||
} | ||
|
||
if (receiverType.isNullable) { | ||
accept('error', "The receiver can be null so a safe access must be used.", { | ||
node, | ||
code: CODE_MEMBER_ACCESS_MISSING_NULL_SAFETY, | ||
}); | ||
} | ||
}; | ||
if (receiverType.isNullable) { | ||
accept('error', 'The receiver can be null so a safe access must be used.', { | ||
node, | ||
code: CODE_MEMBER_ACCESS_MISSING_NULL_SAFETY, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters