Closed Gronne closed 3 years ago
@idhugoid I have created the Issue now
Could you post the smallest example spec that shows this, please? The following does not give an error:
class A
operations
public A: nat ==> A
A(-) == skip;
public A: char ==> A
A(-) == skip;
end A
I think this should recreate it
` class CityMap types
instance variables
interMap_ : nat;
roadMap_ : char;
operations
public CityMap : () ==> CityMap
CityMap() == return self;
public CityMap : nat ==> CityMap
CityMap(interMap) == interMap_ := interMap;
public CityMap : char ==> CityMap
CityMap(roadMap) == roadMap_ := roadMap;
end CityMap `
Nope... Maybe I have a definition another place? Tried to change the name and the error disappeared
Ah OK, maybe something more subtle is going on. Your example doesn't give an error for me (3.0.2 Linux). If you're able to share a spec that shows the problem, that will obviously help a lot! :-)
It might be a mis-location of an error. So perhaps you're using a constructor in an ambiguous way, but instead of highlighting the call, it's highlighting the constructor, which would be confusing?
Ah! This gives an error on the class definition of my example, rather than the constructor call...
test: nat | char ==> A
test(x) ==
return new A(x);
That should be easy to fix. Is something equivalent happening for you?
That's definitely an error in the location of the error(!), and I hope that's all your original problem was. It's trying to say:
Error 3010: Name A((char | nat)) is ambiguous in 'A' (test.vpp) at line 1:7 <--- WRONG LOCATION
1: in 'A' (test.vpp) at line 6:5
2: in 'A' (test.vpp) at line 9:5
But the part of the code that says that no longer knows where the original "new" expression is located, so it defaults to using the location of the class (doh).
I found the problem. The problem is that I have another class where I call the constructor for CityMap. In the constructor call, I am calling a function that has not been created yet (using the TDD development process). Easier to show some code that replicates it:
` class ClassName operations public ClassName : nat ==> ClassName ClassName(arg) == return self;
public ClassName : char ==> ClassName
ClassName(arg) == return self;
end ClassName
class TestClassName
operations
public aFunction : () ==> bool
aFunction() == (
dcl object : ClassName := new ClassName(nothingImplemented);
return is_(object, ClassName);
);
end TestClassName `
OK, I think that is basically the same idea. The type checker presumably does not know the type of "nothingImplemented", so it looks ambiguous, and the error is wrongly reported on the class rather than on the call to "new", which would make more sense.
I'm about to push a fix for the location error. Do you think that covers the problem you're seeing here?
Yes. I will try it out when you have pushed it :)
OK, fix now available in ncb/development:
Error 3010: Name A((char | nat)) is ambiguous in 'T' (test.vpp) at line 18:20 <--- RIGHT LOCATION!
1: in 'A' (test.vpp) at line 6:12
2: in 'A' (test.vpp) at line 9:12
Type checked 2 classes in 0.096 secs. Found 1 type error
Small question... How do I start Overture from the clone? I have only tried to download it from overturetool.org, where an application file is provided
We're not really set up for general users to build it, I'm afraid :( @idhugoid : is it possible to merge ncb/development into a branch that will get built overnight somewhere?
Hi @nickbattle This has just been pushed now. @Gronne you will be able to get a new version from https://overture.au.dk/overture/development/ as soon as build 287 finishes :)
Description
An ambiguity error will occur when making multiple constructors if they have the same number of arguments (even though they are different types).
Steps to Reproduce
Expected behavior: That I can make multiple constructor overloadings with the same amount of arguments as long as they can be distinguished
Actual behavior: Error appears
Reproduces how often: 100% (I guess)
Versions
3.0.2 on Windows 10