ingydotnet/mo-pm

nonlazy switch breaks inheritance?

Opened this issue · 1 comments

I noticed the following strange behaviour regarding the nonlazy option for default values in class hierarchies. Consider the following three files:

A.pm:

package A;
use Mo qw(default);
has foo => 17;
1;

B.pm:

package B;
use Mo qw(default);
extends 'A';
has bar => 42;
1;

use.pl:

#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';

use FindBin;
use lib $FindBin::Bin;
use A;
use B;

my $a = A->new;
say $a->foo;

my $b = B->new;
say $b->foo, $b->bar;

The output is as expected:

$ perl use.pl 
17
1742

Setting the option nonlazy in A.pm, line 2:

use Mo qw(default nonlazy);

leads to this warning;

$ perl use.pl 
17
Use of uninitialized value in say at use.pl line 15.
42

What am I doing wrong?

WL-POOL1-PNT-06947:mo-demo memowe$ perl -MMo -E 'say $Mo::VERSION'
0.40
WL-POOL1-PNT-06947:mo-demo memowe$ perl -V
Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=darwin
    osvers=15.6.0
    archname=darwin-2level
    uname='darwin wl-pool4-pnt-02505.uni-muenster.de 15.6.0 darwin kernel version 15.6.0: thu sep 1 15:01:16 pdt 2016; root:xnu-3248.60.11~2release_x86_64 x86_64 '
    config_args='-de -Dprefix=/Users/memowe/perl5/perlbrew/perls/perl-5.26.0 -Aeval:scriptdir=/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.11 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -DPERL_USE_SAFE_PUTENV'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.11 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -mmacosx-version-min=10.11 -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib
    libs=-lpthread -ldbm -ldl -lm -lutil -lc
    perllibs=-lpthread -ldl -lm -lutil -lc
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' -mmacosx-version-min=10.11 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Locally applied patches:
    Devel::PatchPerl 1.46
  Built under darwin
  Compiled at May 31 2017 14:41:14
  %ENV:
    PERLBREW_BASHRC_VERSION="0.78"
    PERLBREW_HOME="/Users/memowe/.perlbrew"
    PERLBREW_MANPATH="/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/man"
    PERLBREW_PATH="/Users/memowe/perl5/perlbrew/bin:/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/bin"
    PERLBREW_PERL="perl-5.26.0"
    PERLBREW_ROOT="/Users/memowe/perl5/perlbrew"
    PERLBREW_VERSION="0.78"
  @INC:
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0/darwin-2level
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/darwin-2level
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0

This also seems to affect the behaviour with builder.