Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncaught syntax error in classes with sub-functions in Octave 4.2.2 #258

Closed
Remi-Gau opened this issue Jun 27, 2022 · 14 comments
Closed

uncaught syntax error in classes with sub-functions in Octave 4.2.2 #258

Remi-Gau opened this issue Jun 27, 2022 · 14 comments
Labels
component: parser Affects the parser octave support Support features in Octave that do not exist in MATLAB

Comments

@Remi-Gau
Copy link
Contributor

MISS_HIT Component affected

Please choose one from:

  • Style checker
  • Code metrics
  • Documentation

Your MATLAB/Octave environment

  • Octave
  • 4.2.2

Your operating system and Python version

  • linux ubuntu 18.04

Describe the bug

on this repo: https://github.com/cpp-lln-lab/spm_2_bids.git

on the master branch

  • in MATLAB 2017a
>> init_spm_2_bids
Correct matlab/octave verions and added to the path!
>> a = Mapping()

a = 

  Mapping with properties:

          mapping: []
              cfg: [1×1 struct]
              stc: 'a'
          realign: 'r'
           unwarp: 'u'
            coreg: 'r'
         bias_cor: 'm'
             norm: 'w'
           smooth: 's'
    default_value: ''
  • in Octave
>> init_spm_2_bids
Correct matlab/octave verions and added to the path!
>> a = Mapping()
parse error near line 371 of file /home/remi/github/spm_2_bids/src/Mapping.m

  syntax error

>>> function bf = prepare_for_printing(spec)
           ^
@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Jun 27, 2022

not sure if miss_hit should catch this, but opening an issue just in case some other people bump into this down the line.

will try to confirm this on a more recent Octave version and ideally try to provide a MWE.

@Remi-Gau
Copy link
Contributor Author

confirming the failure in CI:

octave fails: https://github.com/cpp-lln-lab/spm_2_bids/runs/7081438354?check_suite_focus=true#step:6:65

  • using moxunit unit github action that runs Octave 4.2.2

matlab passes: https://github.com/cpp-lln-lab/spm_2_bids/runs/7081438195?check_suite_focus=true

@Remi-Gau
Copy link
Contributor Author

MWE and comparison between octave versions

TL;DR:

sub-functions in the same m file that contains a class seem to throw a syntax error with octave 4.2.2 but not 5.1.0


for a m-file containing

classdef Foo

    properties
      closest = 'home'
    end
    
    methods
      
      function obj = Foo()
      end
      
      function next(obj)
        
        bar = obj.closest;
        
        show_me_the_way_to_the_next_whiskey(bar)

      end

    end
    
end


% sub function
function show_me_the_way_to_the_next_whiskey(bar)
  fprintf('next whiskey bar is "%s" \n', bar)
end    

octave 4.2.2

>> a = Foo()
parse error near line 24 of file /home/remi/github/tmp/Foo.m

  syntax error

>>> function show_me_the_way_to_the_next_whiskey(bar)
           ^

>>

octave 5.1.0

>> a = Foo
a =

<object Foo>

>> a.next
next whiskey bar is "home"
>>

matlab 2017a

>> a = Foo()

a = 

  Foo with properties:

    closest: 'home'

>> a.next()
next whiskey bar is "home" 

@Remi-Gau Remi-Gau changed the title uncaught syntax error in Octave uncaught syntax error in classes with sub-functions in Octave 4.2.2 Jun 27, 2022
@florianschanda
Copy link
Owner

So just to make sure I understand this: there is a grammatical construct that is allowed in MATLAB but not Octave, and the issue here is that MISS_HIT should also reject it, if run in Octave mode?

If so, that seems reasonable.

@Remi-Gau
Copy link
Contributor Author

thought I had replied to this. sorry.

So the behavior would be to reject this by default for Octave only. But as this is only a problem for older Octave, it would be nice to be able to ignore this (for people who don't want to support backward compatibility with older Octave).

Another option would be to specify in the miss_hit config which version of matlab or octave the config applies to but I don't think you want to open that can of worms.

@Remi-Gau
Copy link
Contributor Author

forgot to mention that I can provide m-files for the tests: making sure that they fail with octave 4 but not later versions.

I suspect that nested functions in functions and in scripts may also make octave 4 complain.

@florianschanda
Copy link
Owner

If you can post here short snippets from the files (and containing a comment with expectations) that would be super helpful

@florianschanda florianschanda added component: parser Affects the parser octave support Support features in Octave that do not exist in MATLAB labels Aug 9, 2022
@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Aug 9, 2022

Added some files on a branch on my fork: I can open a PR if you want, or I can let you grab them from there.

https://github.com/Remi-Gau/miss_hit/tree/remi_octave_subfunction/tests/octave

@florianschanda
Copy link
Owner

OK, so this is more complex. Basically right now MATLAB means "latest MATLAB" and Octave means "latest Octave". Under this view, everything works.

I do want to add a more complex way to deal with language versions, see e.g. #240 that I haven't touched in a while; and the infrastructure work needed to do that has not been done yet.

I will re-classify the ticket, but please do not expect an immediate fix.

@Remi-Gau
Copy link
Contributor Author

Awesome. Thanks for looking into this.
This is defo not urgent at all: take all the time you need. :-)

@florianschanda
Copy link
Owner

Was it just subfunctions in classdefs files that octave didn't support, or in general? I have been looking over the NEWS files for Octave and I cannot find any mention of this.

@florianschanda
Copy link
Owner

@Remi-Gau could you please test the master branch and see if this now works for your project? CHANGELOG.md should explain how to use the new feature.

@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Oct 11, 2022 via email

@florianschanda
Copy link
Owner

florianschanda commented Oct 20, 2022

But I don't think you want to start to also handle different Octave versions.

The groundwork for this is done. I just need to know which Octave versions support which constructs.

Also do you want me to provide m files to run the tests on for this?

That will always help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: parser Affects the parser octave support Support features in Octave that do not exist in MATLAB
Projects
None yet
Development

No branches or pull requests

2 participants