Article

Compile error 3536 when using undefined datatype with CASE statement

Information

 
Article Number000091360
EnvironmentProduct: OpenEdge
Version: 10.x, 11.x
OS: All supported platforms
Question/Problem Description
When either the expression in the CASE phrase, or the expression in a WHEN phrase is a dynamic construct where the returned type is undefined at compile time, the following compilation error occurs:

Incompatible datatypes in CASE and a WHEN branch expression. (3536)
Steps to Reproduce
Clarifying Information
These variants fail to compile with error 3536:
 
 Common factor is that datatype of expression in CASE is not known at compile time. 
 
DEFINE BUFFER customer FOR customer.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.

FUNCTION testvalue RETURNS INTEGER:
    RETURN RANDOM(1,5000) MOD 2.
END.

FIND FIRST customer.
hBuffer = BUFFER customer:HANDLE.

/* shorthand notation for buffer-value */
CASE hbuffer::custnum: 
    WHEN 1 THEN MESSAGE "one".
    OTHER WISE MESSAGE "not one".
END.      
          
/* long form of above also fails */
CASE hbuffer:BUFFER-FIELD("custnum"):BUFFER-VALUE: 
    WHEN 1 THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END.      
          
/* other  constructs also fail */
CASE DYNAMIC-FUNCTION("testvalue"):
    WHEN  1 THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END CASE. 

/* undefined type on a WHEN branch also fails */        
CASE customer.custnum:   
    WHEN DYNAMIC-FUNCTION("testvalue") THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END CASE.
Error MessageIncompatible datatypes in CASE and a WHEN branch expression. (3536)
Defect/Enhancement Number
Cause
The compiler cannot know what datatype the BUFFER-VALUE attribute will have, since that is only known at runtime.
The BUFFER-VALUE needs to be stored into a known variable type before doing a CASE on it,
The expression in the CASE statement cannot be of indeterminate datatype which is always the case with BUFFER-VALUE.
Resolution
It was determined that the Progress Product is functioning as designed.

An enhancement to the product can be requested through the Progress Community via an Ideas submission. Customer feedback is valuable and Idea submissions are monitored by our Product Management team. Enhancement requests are reviewed during the planning phase of each new product release and a list of the enhancements chosen for implementation can be found in the Release Notes documents that accompany each release. Once an Idea is submitted the Progress Software Community will have the opportunity to comment on and vote for the Idea.

For detailed information on how to submit an Idea, please refer to Knowledge Base article 000010839, "How to submit an idea for a Progress product enhancement".
Workaround
The following variants compile & run normally.

Common factor is that datatype of expression in CASE is known at compile time.
 
/* compiles, works */
CASE customer.custnum:
    WHEN 1 THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END.

/* attribute with fixed data type works.
  (side effect: values get formatted, which affects string comparison)  */ 
CASE hbuffer:BUFFER-FIELD("custnum"):STRING-VALUE: 
    WHEN "1" THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END.

/* explicit cast to fixed data type works */
CASE INT(hbuffer:BUFFER-FIELD("custnum"):BUFFER-VALUE): 
    WHEN 1 THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END.

/* function with fixed return type works */
CASE testvalue():
    WHEN 1 THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END.

/* No WHERE branches -> also works.
   but that's very much a corner case */
CASE DYNAMIC-FUNCTION("testvalue"):
   OTHERWISE MESSAGE "not one".
END CASE.

/* if the WHEN branches also return undefined types, 
   that also works. */
CASE DYNAMIC-FUNCTION("testvalue"):
    WHEN DYNAMIC-FUNCTION("testvalue") THEN MESSAGE "one".
    OTHERWISE MESSAGE "not one".
END CASE.
Notes
Attachment 
Last Modified Date11/16/2018 8:32 AM


Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025