Static method call without New = Error

About Monkey 2 Forums Monkey 2 Development Static method call without New = Error

This topic contains 5 replies, has 4 voices, and was last updated by  abakobo 1 year, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12692

    therevills
    Participant

    Should this work?

    I get “Attempt to invoke method on null instance” using the itch version of v1.1.08.

    #12697

    abakobo
    Participant

    This had changed some months ago. I think it’s to avoid calling uninitialized fields..

    #12717

    Mark Sibly
    Keymaster

    This is because the compiler can’t work out the dependancies involved correctly.

    It does a pretty good job of simpler stuff like:

    …but with your example above, TEST is dependant upon Test.List (so Test.List must be inited first) via the Test.Count function (actually, via a function call *within* the Test.Count function), but the compiler isn’t smart enough to work out dependancies via function calls like this – and probably never will be I’m afraid so I’m not quite sure what the solution is! For now you’ll have to work around it…

    This had changed some months ago. I think it’s to avoid calling uninitialized fields..

    This is unrelated really – it used to be that you could call a method on a null object as long as the method never read/wrote any fields, but no longer. But here, we’re talking about a function, not a method.

    #12718

    therevills
    Participant

    So this use to work?

    In Java its doable, I’m not bothered either way just was trying out nerobot’s preferences code:

    Preferences class

    #12737

    nerobot
    Participant

    It worked for me. But this code is technically equivalent to above one. So it can produce null pointer.

    As a solution for prefs, we can initialize _ptefs field right inside of Get () if it is null.

    Consts initialization is a weak side of monkey2, that may cause errors, so that it’s important to have related remarks in docs.

    (Waiting for a developer that can bring dependency checking.)

    #12749

    abakobo
    Participant

    This is unrelated really

    sorry, have been reading the code too fast..

    Consts initialization is a weak side of monkey2

    Things have been corrected already, what should be mentioned? To me it’s logical that the code would not work even thought “List” is global (I would have called it “LIST”..). But “List” can be declared in head declarations BEFORE “TEST”. It would have the same effect as it global anyway.
    Do you mean that the fact we can’t make some Forward declaration should be documented?
    An example to illustrate my logic (here there’s no class instance but the global is declared in head declarations):

    About Classes documentation, there’s is a lack about Classes functions. They are not mentioned at all and thus it’s not mentioned that Classes’ functions may not use a class field (“Error : Field ‘xxxx’ cannot be accessed without an instance.”)

    As for a practical working example, wouldn’t a function pointer be more “dynamic”. Here there is a class instance which is Const (and containg only global “fields”)..
    Is all this expected behaviour (note the Const Class has it’s field modified, I suppose it’s the reference that is Const)?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.