tracker issue : CF-4202355

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] ER for: Explicitly nullable return types

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): Aaron Neff / ()

Created: 05/10/2018

Components: Language, Null Support

Versions: 2018

Failure Type: Others

Found In Build/Fixed In Build: / 2018,0,0,309297

Priority/Frequency: Normal /

Locale/System: / Platforms All

Vote Count: 1

Issue: Aether Beta's null support allows non-void UDFs to return null. This breaks backward-compat where users expect the declared return type to be enforced.

Suggestion: Require a leading question mark symbol (?) to explicitly indicate a nullable type; otherwise the type is not nullable. Precedent: PHP 7.1.

Examples (with null support enabled):

<cfscript>
  any function myAny1(){}//OK
  any function myAny2(){return}//OK
  any function myAny3(){return null}//OK
  array function myArray1(){}//error
  array function myArray2(){return}//error
  array function myArray3(){return null}//error
  ?array function myArray1(){}//OK
  ?array function myArray2(){return}//OK
  ?array function myArray3(){return null}//OK
</cfscript>

When subtyping a return type the nullability can be removed by a subclass, but it cannot be added:

MyInterface.cfc:
interface {?array function myArray4()}

MyCFC.cfc:
component implements="MyInterface" {array function myArray4(){}}//valid

Related thread: https://forums.adobeprerelease.com/coldfusionpr/discussion/380/cf-4202295-null-support-removes-return-type-check

Related ticket: CF-4202295

Related URL: https://wiki.php.net/rfc/nullable_types

Credit: Adam Cameron, Sean Corfield, Denard Springle and Charlie Arehart.

Attachments:

Comments:

Below is what we have decided to implement - # Null Support Disabled - Old behavior will be retained. # Null Support Enabled - null as return (implicit or explicit) will be allowed only when the return type has been declared as "Any".
Comment by Vijay M.
27750 | May 11, 2018 07:25:39 AM GMT
Hi Vijay and CF Team, Thank you VERY VERY much!!!!!!!!!!! Very!! Thanks!!, -Aaron
Comment by Aaron N.
27773 | May 13, 2018 07:27:34 AM GMT
Hi Vijay, CF-4202295 is actually the original issue. Technically, CF-4202295 should be marked fixed. And this, CF-4202355, should be marked Duplicate of CF-4202295. Yes? Could your comment be copied to CF-4202295 and this ticket closed as duplicate of it? Thanks!, -Aaron
Comment by Aaron N.
27774 | May 13, 2018 07:55:37 AM GMT
Updated status. We will not be supporting the ? array syntax.  Return type check was fixed as part of bug CF-4202295
Comment by Immanuel N.
27912 | May 22, 2018 08:07:13 AM GMT