Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading binary and unary operators #1697

Closed
certik opened this issue May 24, 2023 · 1 comment · Fixed by #1724
Closed

Overloading binary and unary operators #1697

certik opened this issue May 24, 2023 · 1 comment · Fixed by #1724
Assignees
Labels
bug Something isn't working

Comments

@certik
Copy link
Contributor

certik commented May 24, 2023

The bug, reported at https://fortran-lang.discourse.group/t/intel-fortran-compiler-bug-overloading-binary-and-unary-operator-and-use-with-extended-types/5836/10:

module mo_vec
  type :: typ1
    real :: x
  contains
    procedure :: diff, neg
    generic :: operator(-) => diff, neg
  end type typ1
  ! extended type
  type, extends(typ1) :: typ2
  end type typ2
contains
  pure type(typ1) function diff(this, that)
    class(typ1), intent(in) :: this, that
    diff = typ1(this%x-that%x)
  end function diff
  pure type(typ1) function neg(this)
    class(typ1), intent(in) :: this
    neg = typ1(-this%x)
  end function neg
end module mo_vec

program vec_test
  use mo_vec, only: typ2
  type(typ2) :: var1 = typ2(1.), var2 = typ2(2.)
  print *, -var2     ! error #5633: **Internal compiler error
  print *, var1-var2 ! error #6355: This binary operation is invalid for this data type.
end program vec_test

Both the print statements fail for LFortran also.

@certik certik added the bug Something isn't working label May 24, 2023
@czgdp1807 czgdp1807 self-assigned this May 28, 2023
@czgdp1807
Copy link
Member

I am working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants