Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comptime fatal error #1960

Open
disarray2077 opened this issue Apr 27, 2024 · 2 comments
Open

Comptime fatal error #1960

disarray2077 opened this issue Apr 27, 2024 · 2 comments

Comments

@disarray2077
Copy link
Contributor

Introducing a new variable in Span<T> causes a fatal error during comptime evaluation:

---------------------------
FATAL ERROR
---------------------------
FATAL ERROR
Fatal Error in Module: __constEval
Function: ?Init@COMPTIME$?$SplitList@U_T0@@@Collections@System@bf@@CAXXZ
DbgLoc: @3 SplitList.bf:38:12
Malformed structure values in D:\BeefLang\Repository\Beef\IDEHelper\Backend\BeIRCodeGen.cpp:317

image

Tested with: ab31e5b

@bfiete
Copy link
Collaborator

bfiete commented Apr 27, 2024

Ah, yeah. It will definitely still be illegal, but I'll try to make the errors softer.

@kallisto56
Copy link
Contributor

On latest nightly (cfd2bab) this is no longer crashes the IDE. Instead it results in ~60 strange errors.
For example:

ERROR: Method 'BfpFile_Seek' does not exist in type 'System.Platform.Hook'
       at line 14:25 in corlib\src\IO\FileStream.bf

Signature of BfpFile_Seek looks like this:

[CallingConvention(.Stdcall), CLink, StaticHook]
public static extern int64 BfpFile_Seek(BfpFile* file, int64 offset, BfpFileSeekKind seekKind);

By "strange" I mean that methods like BfpFile_Seek have no relation to Span<T>, at least on the surface.
Thankfully, first error in the list that will be printed out during attempt to build it, is about failed comptime, which does hints to user on where the problem may lie:

ERROR: Unable to comptime System.StaticHookAttribute.OnTypeInit(System.Type type, System.StaticHookAttribute* prev) at line 70:3 in ...\corlib\src\Platform.bf
  [StaticHook(typeof(SelfOuter))]
  > Access violation in comptime System.Span<System.StringView>.Enumerator.Current get accessor at line 376:15 in ...\corlib\src\Span.bf
  > in comptime System.Span<System.StringView>.Enumerator.GetNext() at line 415:5 in ...\corlib\src\Span.bf
  > in comptime System.String.Append(params System.Span<System.StringView> strings) at line 1056:4 in ...\corlib\src\String.bf
  > in comptime System.Reflection.TypeInstance.GetFullName(System.String strBuffer) at line 1355:11 in ...\corlib\src\Type.bf
  > in comptime System.Reflection.TypeInstance.GetFullName(System.String strBuffer) at line 1347:8 in ...\corlib\src\Type.bf
  > in comptime System.Reflection.PointerType.GetFullName(System.String strBuffer) at line 1462:4 in ...\corlib\src\Type.bf
  > in comptime System.Type.ToString(System.String strBuffer) at line 993:4 in ...\corlib\src\Type.bf
  > in comptime System.String.AppendF(System.IFormatProvider provider, System.StringView format, params System.Span<System.Object> args) at line 1533:7 in ...\corlib\src\String.bf
  > in comptime System.String.AppendF(System.StringView format, params System.Span<System.Object> args) at line 1564:4 in ...\corlib\src\String.bf
  > in comptime System.StaticHookAttribute.OnTypeInit(System.Type type, System.StaticHookAttribute* prev) at line 69:46 in ...\corlib\src\StaticHookAttribute.bf

Ready-for-testing project: bug.1960.zip
One possible solution (if I may) is to introduce an attribute that disallows new instance fields via extensions.
Last thing: I have an old build from source (14a3dd8) where crash does not occur and extending Span<T> seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants