Euphoria Ticket #104: Forward reference behaves differently from predeclaration

The release notes for Euphoria version 4.0 offer forward referencing. However, forward referencing does not give the same results as pre-declaration. (Fortunately, and very wisely, section 4.2.3 of the manual does not yet offer it.)

In this example, the type declaration notNeg is used before it is declared.

include std/dll.e 
  notNeg K32 = open_dll("kernel32") 
  notNeg NoSuchRtn = define_c_func(K32,"NoSuchRoutine",{},C_UINT) 
type notNeg(atom par) 
  return par > 0 
end type 
 printf(1,"Value of NoSuchRtn = %d\n", NoSuchRtn) 

The result of this example is that the type check does not catch it.
Instead, the output from the program is:

Value of NoSuchRtn is -1 
There is no error dump from the incorrect version.

When the type declaration is moved in front of its use, it behaves correctly.

The following example:

include std/dll.e 
type notNeg(atom par) 
  return par > 0 
end type 
  notNeg K32 = open_dll("kernel32") 
  notNeg NoSuchRtn = define_c_func(K32,"NoSuchRoutine",{},C_UINT) 
  printf(1,"Value of NoSuchRtn = %d\n", NoSuchRtn) 

gives the following error, correctly:

C:\EUPHORIA\include\std\dll.e:476 
type_check failure, NoSuchRtn is -1 

I believe that I have come across other problems with functions rather than types, but I just rearranged the program and have now forgotten them.

Details

Type: Bug Report Severity: Major Category: Interpreter
Assigned To: unknown Status: Fixed Reported Release:
Fixed in SVN #: r3054 View VCS: r3054 Milestone:

1. Comment by DerekParnell Oct 17, 2009

I can recreate the problem and see that incorrect IL code is being generated from your first example. The problem is that it is jumping over the type checking code for the second assignment.

Note that the first assignment is being type checked, and you can see this if you try to open "kernel33" for example.

When you rearrange the code so the type definition comes first, the correct IL code is being generated for both assignments.

2. Comment by mattlewis Jan 22, 2010

This appears to have been fixed. I cannot reproduce this code at all. I've tried inline function calls, regular function calls, direct assignments and built-in calls. Some other change must have corrected the issue.

Search



Quick Links

User menu

Not signed in.

Misc Menu