3 ms·
> But as I can't duplicate it it's entirely possible I was just hallucinating. There's a thing where if you declare a type A, and then a derived type B, method
by msbarnett 11y ago
> But as I can't duplicate it it's entirely possible I was just hallucinating.
There's a thing where if you declare a type A, and then a derived type B, methods on A have to be declared before type B gets declared, because B's declaration "freezes" A. I think it's mostly a single-pass optimization that might have made sense 20 years ago but is meaningless in an era of gigabytes of RAM.
> (Case in point: I've just spent 20 minutes trying to refresh my memory by making this code snippet work. And failing. What am I doing wrong? http://ideone.com/6iPdYF http://ideone.com/6iPdYF)
The specific error message is: you declared a package, which is basically a header in C parlance. You declare signatures in it, not method bodies. Method bodies go in package bodies. You were conflating the package and the package body.
And then from line 19 onwards you were using the package name where you wanted to be using a class name. I cleaned it up a bit and made it work: https://gist.github.com/mbarnett/9c6701fe74524a6df522 https://gist.github.com/mbarnett/9c6701fe74524a6df522
- david-given 11y ago> There's a thing where if you declare a type A, and then a derived type B, methods on A have to be declared before type B gets declared... Yes, that sounds very familiar. > The specific error message is: you declared a package, which is basically a header in C parlance. Oh, FFS. That snippet is not, in fact, pointing at the piece of code I was actually asking about --- ideone changed it when I wasn't looking. The one you saw is unfinished and broken. This one is the one I was meaning: http://ideone.com/skZRIb http://ideone.com/skZRIb The .Foo selector isn't found; changing it to Foo(object) reports that apparently Foo isn't a dispatching method on MyClass1... which makes no sense, because this is the same code as you had. My suspicion is that there's something magic about declaring classes in packages?
- msbarnett 11y ago> which makes no sense, because this is the same code as you had. My suspicion is that there's something magic about declaring classes in packages? Yeah. Dispatching methods on a type consist of the type's "primitive operations". The Ada 95 Rationale spells it out: "Just as in Ada 83, derived types inherit the operations which "belong" to the parent type - these are called primitive operations in Ada 95. User-written subprograms are classed as primitive operations if they are declared in the same package specification as the type and have the type as parameter or result." It seems like a wart that you're not in an "anonymous" package in situations like your example, but I also guess it probably doesn't come up much in "real" programs.