-
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.
feat: various features related to literal types (#657)
Closes partially #80 ### Summary of Changes * Show an error if literal types have no literals * Show an error if lists or maps are used in a literal types * Mark literal types as experimental (show a warning when they are used) * Compute type of manifest literal types * Evaluate literals to a literal type instead of the corresponding class. For example, the literal `1` now gets the type `literal<1>` instead of `Int`). --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
- Loading branch information
1 parent
ca47870
commit 1775705
Showing
47 changed files
with
692 additions
and
171 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { WorkspaceCache } from 'langium'; | ||
import { SafeDsServices } from '../safe-ds-module.js'; | ||
import { SafeDsClasses } from '../builtins/safe-ds-classes.js'; | ||
import { ClassType, Type, UnknownType } from './model.js'; | ||
import { SdsClass } from '../generated/ast.js'; | ||
|
||
export class SafeDsCoreTypes { | ||
private readonly builtinClasses: SafeDsClasses; | ||
private readonly cache: WorkspaceCache<string, Type>; | ||
|
||
constructor(services: SafeDsServices) { | ||
this.builtinClasses = services.builtins.Classes; | ||
this.cache = new WorkspaceCache(services.shared); | ||
} | ||
|
||
get AnyOrNull(): Type { | ||
return this.createCoreType(this.builtinClasses.Any, true); | ||
} | ||
|
||
get Boolean(): Type { | ||
return this.createCoreType(this.builtinClasses.Boolean); | ||
} | ||
|
||
get Float(): Type { | ||
return this.createCoreType(this.builtinClasses.Float); | ||
} | ||
|
||
get Int(): Type { | ||
return this.createCoreType(this.builtinClasses.Int); | ||
} | ||
|
||
get List(): Type { | ||
return this.createCoreType(this.builtinClasses.List); | ||
} | ||
|
||
get Map(): Type { | ||
return this.createCoreType(this.builtinClasses.Map); | ||
} | ||
|
||
/* c8 ignore start */ | ||
get NothingOrNull(): Type { | ||
return this.createCoreType(this.builtinClasses.Nothing, true); | ||
} | ||
/* c8 ignore stop */ | ||
|
||
get String(): Type { | ||
return this.createCoreType(this.builtinClasses.String); | ||
} | ||
|
||
private createCoreType(coreClass: SdsClass | undefined, isNullable: boolean = false): Type { | ||
/* c8 ignore start */ | ||
if (!coreClass) { | ||
return UnknownType; | ||
} | ||
/* c8 ignore stop */ | ||
|
||
const key = `${coreClass.name}~${isNullable}`; | ||
return this.cache.get(key, () => new ClassType(coreClass, isNullable)); | ||
} | ||
} |
Oops, something went wrong.