Compile error: Identifier not found when using NG

BlitzMax Forums/BlitzMax NG/Compile error: Identifier not found when using NG

seriouslee(Posted 2015) [#1]
A function created in a Type extending from an abstract Type is not being identified. Here is the example code:

Abstract Type: filename "gamescene.bmx"


Extending Type: filename "testscene.bmx"


Main file: filename "test.bmx"


When compiled I receive the following:


All files are in the same folder. BMK version is 3.09 mt-win32-x86 / gcc 050100. Testing on Windows 10 using TDM-32-GCC 5.1.0.

This compiles and runs in vanilla Blitzmax. Suggestions?


Derron(Posted 2015) [#2]
It is important to have the classes in separate files.

Think we had a similar issue with "extending" classes some months ago.


BTW: Having "gamescene" and "testscene" in one single file which gets imported by the "test.bmx" ... you get another error:

Compile Error: Cyclic declaration of 'testscene'.



bye
Ron


seriouslee(Posted 2015) [#3]
Thanks for your reply, but I'm not sure I understand: the classes are in separate files. The GameScene class in in a file called "gamescene.bmx", and the TestScene class is in a file called "testscene.bmx". Also, the calling code is in another file called "test.bmx".

Are you referring to something else?


Derron(Posted 2015) [#4]
I just extended your bug report.

If you copy the code from "testscene.bmx" to "gamescene.bmx" and only import "gamescene.bmx" within "test.bmx", the error changes to what I have printed above.


bye
Ron


seriouslee(Posted 2015) [#5]
OK, now I get it :). Thanks.

I've done some additional testing. The following code setup will compile and run with no errors.

File: test.bmx (main file)


File: testscene.bmx


File: gamescene.bmx


Hope that helps.


Derron(Posted 2015) [#6]
The problem lies within this:
a imports b
b imports c

so for "a" "c" is only reachable via "b".
Somewhere in the chain, BCC-NG looses track.


-> created github issue.

bye
Ron


Derron(Posted 2015) [#7]
I would say your bug report was fixed, but my extension is still failing.

Maybe an updated BCC already fixes your issues...


bye
Ron


Brucey(Posted 2015) [#8]
The problem was related to the name of the import matching the name of the type. testscene = testscene. This issue has been resolved in the latest commit.


markcw(Posted 2016) [#9]
Another bug report for NG, similar to this one so I'm posting here.

The issue is that you can't have a function outside a type with the same name as a method in a type. It doesn't seem to matter if it's included, imported, in the same file or if it's a module or not.

Discovered it while trying to build sidesign.minib3d in bmx-ng win7 with tdm mingw 64bit 4.8.1.

Compile Error: Identifier 'CountTriangles' not found.

'Module sidesign.minib3d

Strict

' TSurface.bmx
Type TSurface
	
	Field no_tris:Int=0

	Method CountTriangles:Int()
	
		Return no_tris
	
	End Method
	
	Function RemoveTri(surf:TSurface,tri:Int)
	
		Local no_tris:Int=CountTriangles(surf)
		
	End Function
	
End Type

' functions.bmx
Function CountTriangles:Int(surf:TSurface)
	Return surf.CountTriangles()
End Function



markcw(Posted 2016) [#10]
I have realized this is because the compiler can't tell the difference between the function and the method of the same name.


Brucey(Posted 2016) [#11]
Sure it can. It's just not resolving the scope correctly after it finds a partial match. :-)


markcw(Posted 2016) [#12]
Fixed, thanks very much!

Sidesign.minib3d now builds without changes and I can run many of the examples but not all. Max2d and Maxgui are working though.

I found out LoadMesh/AnimMesh is causing an EAV. The error in debug is:

Unhandled Exception:Attempt to index array element beyond array length

Sorry to go offtopic!


Derron(Posted 2016) [#13]
Which sounds like an "fixable" error ...

You now just have to have a look in the debugger which value fails / returns incorrect content.
Either NG did something unusual or you just found a bug in one of the samples.


bye
Ron


markcw(Posted 2016) [#14]
Ok, I have an example!

LoadAnimMesh calls LoadAnimB3D which calls QuatToMat with a matrix passed as reference (Var). It works ok with a matrix object itself but if the matrix is nested (as a field in the mesh object - globals are ok) then it produces the exception error above.

If you look at the DebugLogs in my example you'll see the mesh.mat pointer is a different value to the mat after passing by reference. The QuatToMat1 function produces the error, the QuatToMat2 shows it works when not passed by reference.

This is another issue with multi-dim arrays. When I changed to a single-dim array there was no error.

'Framework sidesign.minib3d

Strict

'Graphics3D 800,600,0,2

Local mesh:TMesh2=New TMesh2
Local mat:TMatrix2=New TMatrix2

DebugLog "mesh.mat 2="+Byte Ptr(mesh.mat)
mesh.mat=QuatToMat2(mesh.mat)
DebugLog mesh.mat.grid[3,3]

DebugLog "mat="+Byte Ptr(mat)
QuatToMat1(mat)
DebugLog mat.grid[3,3]

DebugLog "mesh.mat 1="+Byte Ptr(mesh.mat)
QuatToMat1(mesh.mat)
DebugLog mesh.mat.grid[3,3]

Function QuatToMat1:TMatrix2(mat:TMatrix2 Var)

	DebugLog "mat 1="+Byte Ptr(mat)
	mat.grid[3,3]=456.0

End Function

Function QuatToMat2:TMatrix2(mat:TMatrix2)

	DebugLog "mat 2="+Byte Ptr(mat)
	mat.grid[3,3]=123.0
	Return mat
	
End Function

Type TMesh2

	Field mat:TMatrix2=New TMatrix2

End Type

Type TMatrix2

	Field grid#[4,4]

End Type



markcw(Posted 2016) [#15]
Thanks again Brucey, great work! :)

Your commit "Fixed passing member var objects by Var" has solved this issue. Tested with Minib3d bones example in x86/x64 debug/release.