Project

General

Profile

Feature #13983

Rational and Complex should be frozen

Added by Eregon (Benoit Daloze) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:83167]

Description

Since they basically are value types.
They also do not support #dup currently:

> 1r.dup
TypeError: can't copy Rational
from `initialize_copy'

> 1i.dup
TypeError: can't copy Complex
from `initialize_copy'

Changing their value can only be considered a semantic bug.

So, let's follow true/false/nil/Integer/Float and friends?

Not sure what #6538 was about but I think Marshal can just freeze after setting the values.
It's slightly incompatible if people do rational.instance_variable_set(:@foo, 1) or so,
but no more than on other now-frozen Numeric types and this kind of code seems highly undesirable.


Related issues

Related to Ruby master - Feature #13985: Avoid exception for #dup/#clone on Rational and ComplexClosedActions

Associated revisions

Revision 42c98194
Added by nobu (Nobuyoshi Nakada) almost 2 years ago

freeze Complex and Rational

  • complex.c (nucomp_s_new_internal, nucomp_loader): Complex
    instances are always frozen now. [Feature #13983]

  • rational.c (nurat_s_new_internal, nurat_loader): Rational
    instances are always frozen now. [Feature #13983]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60214
Added by nobu (Nobuyoshi Nakada) almost 2 years ago

freeze Complex and Rational

  • complex.c (nucomp_s_new_internal, nucomp_loader): Complex
    instances are always frozen now. [Feature #13983]

  • rational.c (nurat_s_new_internal, nurat_loader): Rational
    instances are always frozen now. [Feature #13983]

Revision 60214
Added by nobu (Nobuyoshi Nakada) almost 2 years ago

freeze Complex and Rational

  • complex.c (nucomp_s_new_internal, nucomp_loader): Complex
    instances are always frozen now. [Feature #13983]

  • rational.c (nurat_s_new_internal, nurat_loader): Rational
    instances are always frozen now. [Feature #13983]

Revision 60214
Added by nobu (Nobuyoshi Nakada) almost 2 years ago

freeze Complex and Rational

  • complex.c (nucomp_s_new_internal, nucomp_loader): Complex
    instances are always frozen now. [Feature #13983]

  • rational.c (nurat_s_new_internal, nurat_loader): Rational
    instances are always frozen now. [Feature #13983]

Revision 662fb599
Added by Eregon (Benoit Daloze) almost 2 years ago

Add specs for [Feature #13983] Rational and Complex should be frozen

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60505
Added by Eregon (Benoit Daloze) almost 2 years ago

Add specs for [Feature #13983] Rational and Complex should be frozen

Revision 60505
Added by Eregon (Benoit Daloze) almost 2 years ago

Add specs for [Feature #13983] Rational and Complex should be frozen

Revision 60505
Added by Eregon (Benoit Daloze) almost 2 years ago

Add specs for [Feature #13983] Rational and Complex should be frozen

History

#1

Updated by Eregon (Benoit Daloze) almost 2 years ago

  • Related to Feature #13985: Avoid exception for #dup/#clone on Rational and Complex added
#4

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60214.


freeze Complex and Rational

  • complex.c (nucomp_s_new_internal, nucomp_loader): Complex
    instances are always frozen now. [Feature #13983]

  • rational.c (nurat_s_new_internal, nurat_loader): Rational
    instances are always frozen now. [Feature #13983]

Updated by Eregon (Benoit Daloze) almost 2 years ago

  • Target version set to 2.5

nobu (Nobuyoshi Nakada) wrote:

Applied in changeset trunk|r60214.

Thank you nobu for the patch!

I'll write some specs for it :)

Updated by Eregon (Benoit Daloze) almost 2 years ago

Specs added in r60505

Also available in: Atom PDF