PR# 19424 Finalized C compilation fails for deferred function returning ANY

Problem Report Summary
Submitter: finnianr
Category: Compiler
Priority: High
Date: 2018/01/17
Class: Bug
Severity: Critical
Number: 19424
Release: 16.05
Confidential: No
Status: Analyzed
Responsible:
Environment: linux
Synopsis: Finalized C compilation fails for deferred function returning ANY

Description
I have a program that compiles and works fine in Workbench mode but will not compile to a finalized exe. The problem is with a function `field_value' in class EL_REFLECTED_FIELD which defines the hierarchy shown below. (See attached tar.gz for source) 

	field_value (a_index: INTEGER): ANY
		deferred
		end

In the descendant classes `field_value' is defined as various reference and expanded types, and herein lies the problem. I am getting a string of compilation errors (see attached text fiel) that look like this:

In file included from el2175.c:9:0,
                 from big_file_C44_c.c:27:
el2175.h:12:22: error: conflicting types for 'F2120_19252'
 extern EIF_REFERENCE F2120_19252(EIF_REFERENCE, EIF_REFERENCE);

They all refer to the same function  F2120_19252 which is this:

/* {EL_REFLECTED_FIELD}.value */
EIF_REFERENCE F2120_19252 (EIF_REFERENCE Current, EIF_REFERENCE arg1)
{
bla bla
}

My hunch is that the redefinition from ANY to an expanded type is not being permitted at the C code level because the source files giving errors seem to be all descendants of EL_REFLECTED_FIELD.

EL_REFLECTED_FIELD*
	EL_REFLECTED_EXPANDED_FIELD*
		EL_REFLECTED_NUMERIC_FIELD* [N -> NUMERIC]
			EL_REFLECTED_NATURAL_32
			EL_REFLECTED_INTEGER_64
			EL_REFLECTED_NATURAL_8
			EL_REFLECTED_INTEGER_8
			EL_REFLECTED_INTEGER_16
			EL_REFLECTED_INTEGER_32
			EL_REFLECTED_NATURAL_16
			EL_REFLECTED_NATURAL_64
			EL_REFLECTED_REAL_32
			EL_REFLECTED_REAL_64
		EL_REFLECTED_CHARACTER_8
		EL_REFLECTED_BOOLEAN
		EL_REFLECTED_CHARACTER_32
		EL_REFLECTED_POINTER
	EL_REFLECTED_REFERENCE
		EL_REFLECTED_READABLE*
			EL_REFLECTED_TUPLE
			EL_REFLECTED_STORABLE
		EL_REFLECTED_MAKEABLE_FROM_STRING*
			EL_REFLECTED_MAKEABLE_FROM_ZSTRING
			EL_REFLECTED_MAKEABLE_FROM_STRING_8
				EL_REFLECTED_DATE_TIME
			EL_REFLECTED_MAKEABLE_FROM_STRING_32
		EL_REFLECTED_STRING*
			EL_REFLECTED_STRING_32
			EL_REFLECTED_ZSTRING
			EL_REFLECTED_STRING_8
		EL_REFLECTED_BOOLEAN_REF
To Reproduce

										
Problem Report Interactions
From:finnianr    Date:2018/01/17    Status: Analyzed    Download   
In the end the best solution I found was to define EL_REFLECTED_EXPANDED_FIELD like this

deferred class
	EL_REFLECTED_EXPANDED_FIELD [G]

inherit
	EL_REFLECTED_FIELD

	EL_SHARED_ONCE_STRINGS

feature -- Access

	value (a_object: EL_REFLECTIVE): G
		do
			enclosing_object := a_object
			Result := field_value (index)
		end

feature -- Status query

	is_expanded: BOOLEAN
		do
			Result := True
		end

feature -- Comparison

	are_equal (a_current, other: EL_REFLECTIVE): BOOLEAN
		do
			Result := value (a_current) = value (other)
		end

feature {NONE} -- Implementation

	field_value (i: INTEGER): G
		deferred
		end
end

Then class EL_REFLECTED_BOOLEAN for example, can implement `field_value' like this: 

class
	EL_REFLECTED_BOOLEAN

inherit
	EL_REFLECTED_EXPANDED_FIELD [BOOLEAN]
		rename
			field_value as boolean_field
		end

It finalizes well and conforms to my original intention.

From:finnianr    Date:2018/01/17    Status: Analyzed    Download   
Thanks for the analysis Alexander. I have jettisoned `field_value' and instead just redefined `value' with no class parametrization. 
This has worked and the project will now finalize. 

From:alexk_es    Date:2018/01/17    Status: Analyzed    Download   
There was no issue with `field_value`, but with `value`. In other words, the explicit redeclaration of a function returning one type into a function returning a basic expanded type works, as well as the implicit redeclaration when the result type is formal generic. However, the implicit redeclaration with an anchored result type does not work correctly.

From:finnianr    Date:2018/01/17    Status: Open    Download   
As a workaround I parametrized class EL_REFLECTED_FIELD and the errors went away. This would seem to prove my hunch that the problem is the redefinition from ANY to an expanded type is not possible in finalized C code.

	field_value (a_index: INTEGER): G
		deferred
		end

From:finnianr    Date:2018/01/17    Download   
Attachments for problem report #19424

Attachment: compilation-errors.txt     Size:10257
Attachment: reflection.tar.gz     Size:17906