From 9554a97c509cf6fb8e1c8687190d98b9e9c9e688 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Thu, 26 Oct 2017 10:37:09 +0000 Subject: [PATCH] Throw useful error with .new with no args on natives 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. --- src/Perl6/Metamodel/NativeHOW.nqp | 2 +- t/05-messages/01-errors.t | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Perl6/Metamodel/NativeHOW.nqp b/src/Perl6/Metamodel/NativeHOW.nqp index 88127b8af27..669add3bea2 100644 --- a/src/Perl6/Metamodel/NativeHOW.nqp +++ b/src/Perl6/Metamodel/NativeHOW.nqp @@ -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', diff --git a/t/05-messages/01-errors.t b/t/05-messages/01-errors.t index d4a0aed3b5a..42e66f45a56 100644 --- a/t/05-messages/01-errors.t +++ b/t/05-messages/01-errors.t @@ -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; @@ -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';