Navigation Menu

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

blessing #2757

Closed
p6rt opened this issue May 10, 2012 · 4 comments
Closed

blessing #2757

p6rt opened this issue May 10, 2012 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 10, 2012

Migrated from rt.perl.org#112850 (status was 'rejected')

Searchable as RT112850$

@p6rt
Copy link
Author

p6rt commented May 10, 2012

From @grondilu

Hello,

I failed converting an object derived from Int using bless​:

code​:

class Foo is Int {}; sub somefoo returns Foo { Foo.bless​: 13 }; say somefoo.WHAT;

  Error​:
  rakudo d61049​: OUTPUT«Type check failed for return value␤ in sub
  somefoo at /tmp/42g2EnvfAS​:1␤ in block <anon> at /tmp/42g2EnvfAS​:1␤␤»

$ perl6 --version
This is perl6 version 2012.04.1-9-g110f35c built on parrot 4.3.0 revision RELEASE_4_3_0-12-gf983396

@p6rt
Copy link
Author

p6rt commented Jan 4, 2013

From @moritz

On Thu May 10 06​:12​:35 2012, grondilu@​yahoo.fr wrote​:

I failed converting an object derived from Int using bless​:

code​:

class Foo is Int {}; sub somefoo returns Foo { Foo.bless​: 13 }; say
somefoo.WHAT;

Error&#8203;:
rakudo d61049&#8203;: OUTPUT«Type check failed for return value␤  in sub
somefoo at /tmp/42g2EnvfAS&#8203;:1␤ in block \<anon> at

/tmp/42g2EnvfAS​:1␤␤»

Rakudo is actually correct here​: in Perl 6, bless takes an already-built
object, and does initialization stuff (in particular it calls BUILDALL,
which in turns calls the BUILD submethods or does the default attribute
initialization). So Foo.bless​: 13 actually returns the 13, and that
fails your type check.

So, how does one write the constructor for a class that inherits from a
value type?

A rakudo-specific answer is that you can write

class Foo is Int {
  method new($x) {
  nqp​::box_i($x, self)
  }
}

The spec is silent on how to do it in a more general way.
A possible solution is to force all value types to provide a constructor
that you can inherit. So Int.new(4) would return a 4, but

class Foo is Int { }; Foo.new(4)

would return a 4 but of type Foo.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jan 4, 2013

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jan 4, 2013

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Jan 4, 2013
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant