[Flang] Incorrect diagnose on procedure pointer assignment target being the containing function
Consider the following code:
PROCEDURE(ModFun), POINTER :: ProcPtr
CONTAINS
RECURSIVE FUNCTION ModFun() RESULT(res)
REAL :: ModFun
ProcPtr => ModFun
ModFun = 1.0
END FUNCTION
END
Flang currently issues an error:
./t.f:5:18: error: 'modfun' is already declared in this scoping unit
REAL :: ModFun
^^^^^^
./t.f:4:22: Previous declaration of 'modfun'
RECURSIVE FUNCTION ModFun() RESULT(res)
I can't find anything in the standard that disallow this code.
@llvm/issue-subscribers-flang-frontend
Author: Daniel Chen (DanielCChen)
RECURSIVE FUNCTION ModFun() REAL :: ModFun ProcPtr => ModFun ModFun = 1.0 END FUNCTION
END
Flang currently issues an error:
./t.f:6:5: error: In assignment to procedure pointer 'procptr', the target is not a procedure or procedure pointer ProcPtr => ModFun ^^^^^^^^^^^^^^^^^ ./t.f:5:18: Declaration of 'modfun' REAL :: ModFun ^^^^^^
I can't find anything in the standard that disallow this code.
</details>
@llvm/issue-subscribers-bug
Author: Daniel Chen (DanielCChen)
RECURSIVE FUNCTION ModFun() REAL :: ModFun ProcPtr => ModFun ModFun = 1.0 END FUNCTION
END
Flang currently issues an error:
./t.f:6:5: error: In assignment to procedure pointer 'procptr', the target is not a procedure or procedure pointer ProcPtr => ModFun ^^^^^^^^^^^^^^^^^ ./t.f:5:18: Declaration of 'modfun' REAL :: ModFun ^^^^^^
I can't find anything in the standard that disallow this code.
</details>
The error is valid. The name of ModFun is present in its scope to permit recursive calls.
You are right. The intended code is supposed to be
PROCEDURE(ModFun), POINTER :: ProcPtr
CONTAINS
RECURSIVE FUNCTION ModFun() RESULT(res)
REAL :: res
ProcPtr => ModFun
res = 1.0
END FUNCTION
END