diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5456acf..0d4b26a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ To use development versions of Kipper download the - Implemented internal generic spread argument `T...`, which allows multiple arguments to be passed to a single parameter inside of a generic type specifier. - Implemented constant `NaN`, which represents the `NaN` value in JavaScript (Not a Number). - ([#671](https://github.com/Kipper-Lang/Kipper/issues/671)) + ([#671](https://github.com/Kipper-Lang/Kipper/issues/671)) - New module: - `semantics/runtime-built-ins`, which contains runtime built-in functions, variables and types. - `semantics/runtime-internals`, which contains the runtime internal functions. diff --git a/kipper/core/KipperLexer.g4 b/kipper/core/KipperLexer.g4 index b915d40ec..512ba06a8 100644 --- a/kipper/core/KipperLexer.g4 +++ b/kipper/core/KipperLexer.g4 @@ -88,7 +88,6 @@ False : 'false'; // typeof operator Typeof : 'typeof'; -DefFunc : 'def'; // Constant undefined, void and null identifiers Void : 'void'; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts index b2978826a..9ffece27a 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts @@ -3,7 +3,7 @@ * @since 0.8.0 */ import type { TypeSpecifierExpressionSemantics } from "../type-specifier-expression-semantics"; -import type { Expression } from "../../expression"; +import type { ProcessedType } from "../../../../../semantics"; /** * Semantics for AST Node {@link TypeofTypeSpecifierExpression}. @@ -11,8 +11,8 @@ import type { Expression } from "../../expression"; */ export interface TypeofTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { /** - * The expression to evaluate the type of. - * @since 0.8.0 + * The checked type for this typeof expression. + * @since 0.12.0 */ - object: Expression; + evaluatedType: ProcessedType; } diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts index b43bf7419..a95787d23 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts @@ -8,7 +8,7 @@ import type { CompilableASTNode } from "../../../../compilable-ast-node"; import { TypeSpecifierExpression } from "../type-specifier-expression"; import type { TypeofTypeSpecifierExpressionContext } from "../../../../../lexer-parser"; import { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../lexer-parser"; -import { KipperNotImplementedError } from "../../../../../../errors"; +import { RawType } from "../../../../../semantics"; /** * Typeof type specifier expression, which represents a runtime typeof expression evaluating the type of a value. @@ -81,13 +81,13 @@ export class TypeofTypeSpecifierExpression extends TypeSpecifierExpression< * the children has already failed and as such no parent node should run type checking. */ public async primarySemanticAnalysis(): Promise { - const objectToValidate = this.children[0]; + const expression = this.children[0]; this.programCtx.semanticCheck(this); this.semanticData = { - object: objectToValidate, - rawType: objectToValidate.getTypeSemanticData().evaluatedType, + evaluatedType: expression.getTypeSemanticData().evaluatedType, + rawType: new RawType(expression.sourceCode) }; } @@ -102,7 +102,7 @@ export class TypeofTypeSpecifierExpression extends TypeSpecifierExpression< this.programCtx.semanticCheck(this); this.typeSemantics = { - storedType: semanticData.object.getTypeSemanticData().evaluatedType, + storedType: semanticData.object.g, evaluatedType: semanticData.object.getTypeSemanticData().evaluatedType, }; } diff --git a/test/kipper-files/typeof.kip b/test/kipper-files/typeof.kip index eec157018..aff666fe5 100644 --- a/test/kipper-files/typeof.kip +++ b/test/kipper-files/typeof.kip @@ -1,9 +1,6 @@ interface X { - a: str; - b: num; -} - -var y: X = { - a: "hello", - b: 5 + a: num; + b: str; }; + +var x: typeof(null);