Intel Fortran Classic 2021报错#6633:实参与虚参类型不匹配问题排查
提问内容
我有一个定义了自定义Type及其配套方法的模块,同时还包含若干与该Type无关的通用方法。
module TypeDef type, public :: T ... contains ... procedure type_proc end type ... contains !module subroutine type_proc( this, ... ) class(T), target :: this ... call gen_proc( arg_1, arg_n-1, this, arg_n+1 ) ... end subroutine type_proc ... subroutine gen_proc( arg_1, ..., arg_n-1, tv, arg_n+1 ) ! 这是一个通用模块子程序 ! 与自定义类型无绑定关系 implicit none ... class(T), pointer, intent(in) :: tv ... if ( cond ) tv%member = 0 ... end subroutine gen_proc end module
我通过type(T), public :: var变量调用其成员方法type_proc(),该方法内部会调用模块通用过程gen_proc(),需要在gen_proc()中根据条件修改发起方法调用的实际对象(即var)的成员。为此我将this作为常量指针传入gen_proc(),以传递对象地址访问其成员。
但编译时触发了上述#6633错误,改为按引用而非常量指针传递也出现相同报错。
我暂未发现代码存在错误,此前查到的Intel Fortran error #6633: The type of the actual argument differs from the type of the dummy argument同类报错场景中,调用发生在不同程序单元,与我的情况不符。
编辑2
我写的以下简化测试代码可正常编译运行:
module test type, public :: T real, allocatable :: m1(:) real, allocatable :: m2(:) integer :: may_change contains procedure :: t_proc procedure :: all_t end type private :: all_t contains subroutine t_proc( this, n ) implicit none class(T), target :: this integer, intent(in) :: n call this%all_t( n ) call gen_proc( n, this%m1, this%m2, this ) end subroutine t_proc subroutine all_t( this, n ) implicit none class(T) :: this integer, intent(in) :: n allocate( this%m1( n ) ) allocate( this%m2( n ) ) end subroutine subroutine gen_proc( n, m1, m2, Tt ) implicit none integer, intent(in) :: n real, intent(in) :: m1(n), m2(n) class(T), intent(in), pointer :: Tt if ( .true. ) Tt%may_change = 1 print *, ' may change = ', Tt%may_change end subroutine gen_proc end module test module varmod use test type(T), public :: var end module varmod program main use varmod, only: var implicit none integer, parameter :: n = 2 var%may_change = 0 call var%t_proc( n ) end program main
因此我更不清楚实际业务代码的问题出在哪里,求排查思路。
排查思路
- 排查类型符号冲突:确认当前模块内没有重复定义
T类型,也没有通过use其他模块引入了同名的T类型导致符号覆盖,Intel编译器对同名类型的冲突提示不明确,常直接抛出参数类型不匹配错误。 - 核对参数声明匹配:检查
gen_proc接收T类型参数的虚参声明,确认使用的是class(T)而非type(T),和实参this的多态属性一致;同时检查参数的pointer/target/allocatable属性是否匹配。 - 确认参数顺序正确:核对调用
gen_proc时的入参顺序和虚参声明顺序完全一致,避免参数位置写串导致其他类型的变量被传入T类型参数的位置。 - 检查隐式类型问题:确认所有程序单元都声明了
implicit none,避免因变量拼写错误被编译器默认推断为整型,触发类型不匹配报错。 - 验证成员访问权限:确认你在
gen_proc中修改的T类型成员是public属性,若成员被声明为private,部分版本的Intel编译器可能会误报为类型不匹配错误而非访问权限错误。 - 排查编译器版本问题:如果上述所有项都确认无误,可以尝试升级Intel Fortran编译器版本,旧版本ifort对多态类参数的类型校验存在已知的误判bug。
内容的提问来源于stack exchange,提问作者mEm
相关产品推荐
相关产品推荐

