Skip to content

Commit

Permalink
Throw useful error with .new with no args on natives
Browse files Browse the repository at this point in the history
This form never worked, so we don't need to bother passing it
via deprecation period. Just start throwing same error all forms
will be throwing once deprecation period expires.
  • Loading branch information
zoffixznet committed Oct 26, 2017
1 parent 2c4868b commit 9554a97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/NativeHOW.nqp
Expand Up @@ -116,7 +116,7 @@ class Perl6::Metamodel::NativeHOW
method method_table($obj) {
nqp::hash('new',
nqp::getstaticcode(sub (*@_,*%_) {
# nqp::die('Cannot instantiate a native type');
@_[1] // nqp::die('Cannot instantiate a native type');
nqp::getlexcaller('&DEPRECATED')(
'(my ' ~ @_[0].HOW.name(@_[0]) ~ ' $ = ' ~ @_[1].perl() ~ ')',
'2017.09.403',
Expand Down
14 changes: 13 additions & 1 deletion t/05-messages/01-errors.t
Expand Up @@ -262,7 +262,7 @@ throws-like 「callframe.callframe(1).my.perl」, X::NYI,


subtest '.new on native types works (deprecated; will die)' => {
plan 9;
plan 18;

die "Time to remove deprecation and make .new on ints die"
if $*PERL.compiler.version after v2017.12.50;
Expand All @@ -286,6 +286,18 @@ subtest '.new on native types works (deprecated; will die)' => {

is-deeply str.new('x'), 'x', 'str';

throws-like { int .new }, Exception, :message{.contains: "Cannot instantiate"}, 'int no args';
throws-like { int8 .new }, Exception, :message{.contains: "Cannot instantiate"}, 'int8 no args';
throws-like { int16.new }, Exception, :message{.contains: "Cannot instantiate"}, 'int16 no args';
throws-like { int32.new }, Exception, :message{.contains: "Cannot instantiate"}, 'int32 no args';
throws-like { int64.new }, Exception, :message{.contains: "Cannot instantiate"}, 'int64 no args';

throws-like { num .new }, Exception, :message{.contains: "Cannot instantiate"}, 'num no args';
throws-like { num32.new }, Exception, :message{.contains: "Cannot instantiate"}, 'num32 no args';
throws-like { num64.new }, Exception, :message{.contains: "Cannot instantiate"}, 'num64 no args';

throws-like { str.new }, Exception, :message{.contains: "Cannot instantiate"}, 'str no args';

# throws-like { int .new: 4 }, Exception, 'int';
# throws-like { int8 .new: 4 }, Exception, 'int8';
# throws-like { int16.new: 4 }, Exception, 'int16';
Expand Down

0 comments on commit 9554a97

Please sign in to comment.