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

duplicate methods with the same name but different return types #771

Closed
vahdat-ab opened this Issue Mar 12, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@vahdat-ab
Copy link
Member

commented Mar 12, 2016

Umple accepts the following example:

class A{
  void test1(){
  }
  Integer test1(){ 
  }
}

It is not acceptable in Java and C++ to have two methods with the same name and different return types. I'm not sure about othe languages but Umple should avoid generating a wrong code.

@vahdat-ab vahdat-ab changed the title duplicate methods with the same name but different return type duplicate methods with the same name but different return types Mar 12, 2016

@TimLethbridge TimLethbridge added the ucosp label Sep 20, 2016

@TimLethbridge

This comment has been minimized.

Copy link
Member

commented Jan 16, 2017

Should return a warning for sure.

@a3994288

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2017

If I have duplicated methods that return the SAME types, a warning will be generated.
class A{ void test1(){} void test1(){} }

A implementation of Method 'test1' in class 'A' is already defined at line 3 of 'model.ump' file. New definition at line 5 of 'model.ump' file is being disconsidered. More information (49)

This warning has not been developed in user manual yet, so I assume I should document the warning in user manual if I like to use it.

I have two solutions to propose:

  1. Can I just re-use the warning above, generate a warning for duplicated method name (regardless of whether it returns the same type or not)

  2. generate separate warning for the situation described in the issue, which means when they return different types, I only generate a warning for those languages that does not support it (like Java)

I personally support 1st propose as I believe use the same method name in the same package is not necessary for any language and can be achieved by other approaches.

Please let me know if I am on the right track, and also I am still not sure where should I fix it in the code. Could someone point out where should I make changes in the code or which document I should read?(I've been reading a lot documentations those days but still don't have a clue)

@vahdat-ab

This comment has been minimized.

Copy link
Member Author

commented Jan 17, 2017

I would say first document the error code 49. Don't forget to point out this in you PR's comment because Tim needs to review the text.
solution 2 is not the case. We are not targeting a specific language at the modeling language. Therefore, Umple' modeling syntax and semantics are not going to depend on a specific language.
The above case must be avoided all the time.
I am more in supporting of having a separate error code which describes the error more clearly. The error code 49 says methods are exactly the same, but the new one might say they have the same name and parameters but different return types which are not acceptable in Umple.

@vahdat-ab

This comment has been minimized.

Copy link
Member Author

commented Jan 17, 2017

Regarding the place to start, please checkUmple.ump and Umple_Code.ump regarding how a method is structured and compared with others. Then you can check UmpleInternalParser_Code.ump for the exact place to find. To me, you just need to modify the comparison algorithm to consider the return type.

@a3994288

This comment has been minimized.

Copy link
Contributor

commented Jan 21, 2017

#457 return warning 049 when methods have the same return types and names. For this issue, I will modify his code to (in UmpleInternalParser_CodeClass.ump):
If (have same name and paras) {if(same type) return warning 049 else return warning 071}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.