view test/bug-45351/bug45351.m @ 26796:45fc6505a803

allow handles to methods created inside method or ctor to work (bug #45351) * ov-fcn-handle.cc (make_fcn_handle): If currently inside a method or constructor, check for methods of the current class before other functions. * test/bug-45351/bug-45351.tst, bug-45351/bug45351.m, bug-45351/module.mk: New test files. * test/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2019 20:27:38 +0000
parents
children
line wrap: on
line source

classdef bug45351

  properties (Hidden, SetAccess = protected)
    h1 = [];% handle to function
    h2 = [];% handle to function
    h3 = [];% handle to function
  end

  methods
    function self = bug45351 ()
      self.h1 = @foo;
      self.h2 = @(self, n) self.foo (n);
      self.h3 = @(~, n) self.foo (n);
    end
    function [h1, h2, h3] = get_handles (self)
      h1 = self.h1;
      h2 = self.h2;
      h3 = self.h3;
    end
    function r = bar (self, hnum)
      switch (hnum)
        case 1
          r = self.h1 (self, hnum);
        case 2
          r = self.h2 (self, hnum);
        case 3
          r = self.h3 (self, hnum);
      end
    end
  end

  methods (Hidden, Access = protected)
    function r = foo (self, n)
      r = sprintf ('bug45351.foo: %d', n);
    end
  end
end