diff --git a/std/jule/build/log.jule b/std/jule/build/log.jule index f71882386..e4891f988 100644 --- a/std/jule/build/log.jule +++ b/std/jule/build/log.jule @@ -239,6 +239,7 @@ enum LogMsg: str { ArraySizeOverflow: "array with size @ overflows limit (@) of the system", InvalidTypeForTypeOf: "comptime::TypeOf is not supports type @", ComptimeAsExpr: "compile-time evaluations cannot used as expression", + InvalidTypeForFn: `type @ is invalid for function @`, // Suggestions. ExpectedIdentifier: `write an identifier because identifier expected`, diff --git a/std/jule/sema/builtin.jule b/std/jule/sema/builtin.jule index cb2bde337..f83151229 100644 --- a/std/jule/sema/builtin.jule +++ b/std/jule/sema/builtin.jule @@ -852,6 +852,9 @@ fn builtinCallerStdMemSizeOf(mut &e: &Eval, mut &fc: &FnCallExpr, mut &_: &Data) if d == nil { ret result } + if !validTypeForXof(d.Kind) { + e.pushErr(fc.Args[0].Token, LogMsg.InvalidTypeForFn, d.Kind.Str(), "SizeOf") + } result.Model = &SizeofExprModel{Expr: d.Model} ret result @@ -874,6 +877,9 @@ fn builtinCallerStdMemAlignOf(mut &e: &Eval, mut &fc: &FnCallExpr, mut &_: &Data if d == nil { ret result } + if !validTypeForXof(d.Kind) { + e.pushErr(fc.Args[0].Token, LogMsg.InvalidTypeForFn, d.Kind.Str(), "AlignOf") + } result.Model = &AlignofExprModel{Expr: d.Model} ret result diff --git a/std/jule/sema/type.jule b/std/jule/sema/type.jule index 165ab4e2e..0313b9c8a 100644 --- a/std/jule/sema/type.jule +++ b/std/jule/sema/type.jule @@ -1739,4 +1739,8 @@ fn applyImplicitCast(mut &dest: &TypeKind, mut &d: &Data) { applyCastKindModel(d, dest) ret } +} + +fn validTypeForXof(mut &t: &TypeKind): bool { + ret !t.Void() && t.Fn() == nil } \ No newline at end of file diff --git a/std/mem/builtin.jule b/std/mem/builtin.jule index f32489245..72775c9d6 100644 --- a/std/mem/builtin.jule +++ b/std/mem/builtin.jule @@ -4,11 +4,13 @@ // Returns the size of the type in bytes. // If given expression, uses type of expression. +// Void and function types are not supported. // fn SizeOf(TYPE || EXPRESSION): uint // Returns the alignment, in bytes, required for any instance of the type // indicated by type-id, which is either complete object type. // If given expression, uses type of expression. +// Void and function types are not supported. // fn AlignOf(TYPE || EXPRESSION): uint // Frees memory.