Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.84k stars 524 forks source link

scalar operator does not change void context #2011

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#3286 (status was 'resolved')

Searchable as RT3286$

p5pRT commented 23 years ago

From @ysth

Created by @ysth

The scalar operator does not change void context.

[D​:\home\sthoenna]perl #!perl -wl sub context { print wantarray ? 'list' : defined wantarray ? 'scalar' : 'void'} my @​x = scalar context; # works my $x = scalar context; # works scalar context; # doesn't work __END__ scalar scalar void

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.6.0: Configured by sthoenna at Thu Mar 23 16:36:26 PST 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=os2, osvers=2.30, archname=os2 uname='os2 efn.org 2 2.30 i386 ' config_args='-de -Dprefix=d:/perl -Aoptimize=-DDEBUGGING' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='gcc', optimize='-O2 -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2 -s -DDEBUGGING', gccversion=2.8.1 cppflags='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' ccflags ='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, usemymalloc=y, prototype=define Linker and Libraries: ld='gcc', ldflags ='-Zexe -Zomf -Zmt -Zcrtdll -Zstack 32000' libpth=d:/emx/lib d:/emx/lib/mt libs=-lsocket -lm -lbsd libc=d:/emx/lib/mt/c_import.lib, so=dll, useshrplib=true, libperl=libperl.lib Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-Zdll', lddlflags='-Zdll -Zomf -Zmt -Zcrtdll -s' Locally applied patches: @INC for perl v5.6.0: d:/perl/lib/5.6.0/os2 d:/perl/lib/5.6.0 d:/perl/lib/site_perl/5.6.0/os2 d:/perl/lib/site_perl/5.6.0 d:/perl/lib/site_perl . Environment for perl v5.6.0: HOME=d:\home\sthoenna LANG=en_us LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=d:\bin;C:\OS2;d:\perl\bin;C:\OS2\SYSTEM;C:\OS2\INSTALL;C:\;C:\OS2\MDOS;C:\OS2\APPS;C:\MMOS2;d:\os2apps\util;d:\DOSAPPS\UTIL;c:\sio;D:\WINDOWS;d:\pdksh;d:\emx\bin;d:\emacs\19.33\bin;d:\ispell PERL_BADLANG (unset) PERL_SH_DIR=d:\BIN SHELL (unset) ```
p5pRT commented 23 years ago

From @ysth

Created by @ysth

The scalar operator does not change void context.

[D​:\home\sthoenna]perl #!perl -wl sub context { print wantarray ? 'list' : defined wantarray ? 'scalar' : 'void'} my @​x = scalar context; # works my $x = scalar context; # works scalar context; # doesn't work __END__ scalar scalar void

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.6.0: Configured by sthoenna at Thu Mar 23 16:36:26 PST 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=os2, osvers=2.30, archname=os2 uname='os2 efn.org 2 2.30 i386 ' config_args='-de -Dprefix=d:/perl -Aoptimize=-DDEBUGGING' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='gcc', optimize='-O2 -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2 -s -DDEBUGGING', gccversion=2.8.1 cppflags='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' ccflags ='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, usemymalloc=y, prototype=define Linker and Libraries: ld='gcc', ldflags ='-Zexe -Zomf -Zmt -Zcrtdll -Zstack 32000' libpth=d:/emx/lib d:/emx/lib/mt libs=-lsocket -lm -lbsd libc=d:/emx/lib/mt/c_import.lib, so=dll, useshrplib=true, libperl=libperl.lib Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-Zdll', lddlflags='-Zdll -Zomf -Zmt -Zcrtdll -s' Locally applied patches: @INC for perl v5.6.0: d:/perl/lib/5.6.0/os2 d:/perl/lib/5.6.0 d:/perl/lib/site_perl/5.6.0/os2 d:/perl/lib/site_perl/5.6.0 d:/perl/lib/site_perl . Environment for perl v5.6.0: HOME=d:\home\sthoenna LANG=en_us LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=d:\bin;C:\OS2;d:\perl\bin;C:\OS2\SYSTEM;C:\OS2\INSTALL;C:\;C:\OS2\MDOS;C:\OS2\APPS;C:\MMOS2;d:\os2apps\util;d:\DOSAPPS\UTIL;c:\sio;D:\WINDOWS;d:\pdksh;d:\emx\bin;d:\emacs\19.33\bin;d:\ispell PERL_BADLANG (unset) PERL_SH_DIR=d:\BIN SHELL (unset) ```
p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Yitzchak Scott-Thoennes writes​:

sub context { print wantarray ? 'list' : defined wantarray ? 'scalar' : 'void'} my @​x = scalar context; # works my $x = scalar context; # works scalar context; # doesn't work __END__ scalar scalar void

What bothers you? void context is a (kind of a) scalar context.

Ilya

p5pRT commented 23 years ago

From @simoncozens

The scalar operator does not change void context.

This is because Perl_scalarvoid makes the scalar operator impart void context on its children. This seems extremely wrong indeed.

Inline Patch ```diff --- ../op.c Tue May 30 03:45:39 2000 +++ op.c Tue May 30 03:42:21 2000 @@ -1160,7 +1160,6 @@ case OP_DBSTATE: case OP_ENTERTRY: case OP_ENTER: - case OP_SCALAR: if (!(o->op_flags & OPf_KIDS)) break; /* FALL THROUGH */ @@ -1179,6 +1178,7 @@ case OP_REQUIRE: /* all requires must return a boolean value */ o->op_flags &= ~OPf_WANT; + case OP_SCALAR: return scalar(o); case OP_SPLIT: if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) { --- t/op/wantarray.t~ Tue May 30 03:48:07 2000 +++ t/op/wantarray.t Tue May 30 03:49:50 2000 @@ -1,6 +1,6 @@ #!./perl -print "1..3\n"; +print "1..7\n"; sub context { my ( $cona, $testnum ) = @_; my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V'; @@ -13,4 +13,8 @@ context('V',1); $a = context('S',2); @a = context('A',3); +scalar context('S',4); +$a = scalar context('S',5); +($a) = context('A',6); +($a) = scalar context('S',7); 1; ---------------------------------------------------------------- ```

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review\, retransmission\, dissemination or other use of\, or taking of any action in reliance upon\, this information by persons or entities other than the intended recipient is prohibited. If you received this in error\, please contact the sender and delete the material from any computer.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Created by @ysth

The scalar operator does not change void context.

[D​:\home\sthoenna]perl #!perl -wl sub context { print wantarray ? 'list' : defined wantarray ? 'scalar' : 'void'} my @​x = scalar context; # works my $x = scalar context; # works scalar context; # doesn't work __END__ scalar scalar void

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.6.0: Configured by sthoenna at Thu Mar 23 16:36:26 PST 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=os2, osvers=2.30, archname=os2 uname='os2 efn.org 2 2.30 i386 ' config_args='-de -Dprefix=d:/perl -Aoptimize=-DDEBUGGING' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='gcc', optimize='-O2 -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2 -s -DDEBUGGING', gccversion=2.8.1 cppflags='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' ccflags ='-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -D_EMX_CRT_REV_=62' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, usemymalloc=y, prototype=define Linker and Libraries: ld='gcc', ldflags ='-Zexe -Zomf -Zmt -Zcrtdll -Zstack 32000' libpth=d:/emx/lib d:/emx/lib/mt libs=-lsocket -lm -lbsd libc=d:/emx/lib/mt/c_import.lib, so=dll, useshrplib=true, libperl=libperl.lib Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-Zdll', lddlflags='-Zdll -Zomf -Zmt -Zcrtdll -s' Locally applied patches: @INC for perl v5.6.0: d:/perl/lib/5.6.0/os2 d:/perl/lib/5.6.0 d:/perl/lib/site_perl/5.6.0/os2 d:/perl/lib/site_perl/5.6.0 d:/perl/lib/site_perl . Environment for perl v5.6.0: HOME=d:\home\sthoenna LANG=en_us LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=d:\bin;C:\OS2;d:\perl\bin;C:\OS2\SYSTEM;C:\OS2\INSTALL;C:\;C:\OS2\MDOS;C:\OS2\APPS;C:\MMOS2;d:\os2apps\util;d:\DOSAPPS\UTIL;c:\sio;D:\WINDOWS;d:\pdksh;d:\emx\bin;d:\emacs\19.33\bin;d:\ispell PERL_BADLANG (unset) PERL_SH_DIR=d:\BIN SHELL (unset) ```