sourcepawn icon indicating copy to clipboard operation
sourcepawn copied to clipboard

compiler crashing when not using () for a methodmap's native

Open Dolly132 opened this issue 3 months ago • 2 comments

When not using () to call the native, the compiler crashes and doesn't manage to compile the code. For example here with entitylump:

for(int i = 0; i < EntityLump.Length; i++)

This crashes the compiler because the method "Length` is a native and not a property. considering that most methodmaps use this name as a property which led me to use it without () thinking it was a property

But when using: for(int i = 0; i < EntityLump.Length(); i++)

The compiler works fine as expected and the code manages to be compiled.

Compiler Version: SourcePawn Compiler 1.12.0.7210 Copyright (c) 1997-2006 ITB CompuPhase Copyright (c) 2004-2024 AlliedModders LLC

Dolly132 avatar Aug 31 '25 06:08 Dolly132

Do you have an example script? I can't repro with:

methodmap Blah {
  public int Length() { return 2; }
}

public void main() {
  Blah blah;
  for (int i = 0; i < blah.Length; i++) {
  }
}

Output:

test.sp(7) : error 050: missing function call, cannot use non-static member function as a value
     7 |   for (int i = 0; i < blah.Length; i++) {
-----------------------------------^

1 Error.

dvander avatar Sep 13 '25 20:09 dvander

Do you have an example script? I can't repro with:

methodmap Blah {
  public int Length() { return 2; }
}

public void main() {
  Blah blah;
  for (int i = 0; i < blah.Length; i++) {
  }
}

Output:

test.sp(7) : error 050: missing function call, cannot use non-static member function as a value
     7 |   for (int i = 0; i < blah.Length; i++) {
-----------------------------------^

1 Error.

I guess it only happens for static methods/members Try using EntityLump's methodmap, the compiler will crash. If you removed static from the Length native, it will work just fine and throw an error like in your example.

(Sorry for the late reply)

Dolly132 avatar Nov 09 '25 09:11 Dolly132