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

Bogus warning about ambiguous method #1191

Closed
cpyrgas opened this issue Dec 13, 2022 · 4 comments
Closed

Bogus warning about ambiguous method #1191

cpyrgas opened this issue Dec 13, 2022 · 4 comments

Comments

@cpyrgas
Copy link

cpyrgas commented Dec 13, 2022

Following code (taken from real user code) reports 2 warnings:

warning XS9043: 'Equals' is ambiguous. Could be Method 'TestClass.Equals(int)' in xRuntime or Method 'object.Equals(object)' in mscorlib. Using the first one.
warning XS9043: 'Equals' is ambiguous. Could be Method 'AnotherClass.Equals(AnotherClass)' in xRuntime or Method 'object.Equals(object)' in mscorlib. Using the first one.

bu there's no ambiguity, the child method defines the parameter with the same type that is passed to it, so this is the one that should laways be picked. Same code in c# does not report any errors or warnings.

FUNCTION Start() AS VOID
	LOCAL o := TestClass{} AS TestClass
	o:Equals(123)
	
	LOCAL a := AnotherClass{} AS AnotherClass
	a:Equals(a)
RETURN

CLASS TestClass
	METHOD Equals(n AS INT) AS LOGIC
		? "called child"
	RETURN TRUE
END CLASS

CLASS AnotherClass
	METHOD Equals(o AS AnotherClass) AS LOGIC
		? "called child"
	RETURN TRUE
END CLASS
@cpyrgas
Copy link
Author

cpyrgas commented Dec 14, 2022

Problem does not exist in Core dialect

cpyrgas pushed a commit to X-Sharp/XSharpDev that referenced this issue Dec 14, 2022
@RobertvanderHulst RobertvanderHulst added this to To do in Build 2.15 - fixes in X# 2 via automation Dec 14, 2022
@RobertvanderHulst RobertvanderHulst self-assigned this Dec 27, 2022
RobertvanderHulst added a commit to X-Sharp/XSharpDev that referenced this issue Dec 27, 2022
@RobertvanderHulst RobertvanderHulst added this to To do in Build 2.15 - fixes in X# 2 via automation Dec 27, 2022
@RobertvanderHulst RobertvanderHulst moved this from To do to Needs testing in Build 2.15 - fixes in X# 2 Dec 27, 2022
@cpyrgas
Copy link
Author

cpyrgas commented Jan 6, 2023

I'm still getting this one. Robert, I think you cheated by changing the test's Dialect to Core :)

@cpyrgas cpyrgas moved this from Needs testing to In progress in Build 2.15 - fixes in X# 2 Jan 6, 2023
@RobertvanderHulst RobertvanderHulst moved this from In progress to Needs testing in Build 2.15 - fixes in X# 2 Jan 17, 2023
@cpyrgas
Copy link
Author

cpyrgas commented Jan 17, 2023

Just adding another case, as reported in https://www.xsharp.eu/forum/private-product/3329-2-14-0-4-compiler-errors-xs0121-and-xs1503#25003. Will test the updated compiler afterwards.

CLASS TestClass
END CLASS

CLASS Parent
VIRTUAL METHOD Add(o AS OBJECT) AS INT
RETURN 0
END CLASS

CLASS Child INHERIT Parent
METHOD Add(o AS TestClass) AS VOID
END CLASS

CLASS MyCollection INHERIT System.Collections.ArrayList
	METHOD Add(o AS TestClass) AS VOID
END CLASS

FUNCTION Start() AS VOID
	LOCAL t := NULL AS TestClass

	Child{}:Add(t) // no warning, OK
	
	MyCollection{}:Add(t) // warning XS9043: 'Add' is ambiguous. Could be Method 'MyCollection.Add(TestClass)' in xRuntime or Method 'System.Collections.ArrayList.Add(object)' in mscorlib. Using the first one.
RETURN

RobertvanderHulst added a commit to X-Sharp/XSharpDev that referenced this issue Jan 18, 2023
* [Compiler tests] Adjusted tests for X-Sharp/XSharpPublic#1187 and X-Sharp/XSharpPublic#1191

* [Compiler tests] Added C877 and adjusted R882 for X-Sharp/XSharpPublic#1184

* [Compiler tests] Added C878 for X-Sharp/XSharpPublic#1194 (and missing C877 from previous commit)

* [Common] Fixes #X-Sharp/XSharpPublic/issues/1194

* WIP on StackAlloc, debugger sequence points and line numbers in error messages

* [Compiler tests] Added test C879 for X-Sharp/XSharpPublic#1195

* [Compiler] Switch to .Net Analyzers version 7.0.0

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/1195
Adjust overload resolution to only use our "logic" when:
- functions are involved
- our types are involved
- param is passed by reference
- argument is enum

* [Compiler] Suppress error messages about updated NetAnalyzers. Also suppress NetAnalyzer all together for X# code

* [Tests] Fixed one more test

* Fixes #X-Sharp/XSharpPublic/issues/1184, C877 and R882

* [Tests] SUM command has been fixed in the header file

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/1084

* [Tests] Added test for Stackalloc keyword

* [Compiler] A predicate prevents STACKALLOC(123) from being parsed as STACKALLOC followed by a paren expression

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/1166, issue number 1

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/1109

* [Tests] Added pragma to several tests to suppress messages about missing REF or OUT modifiers for parameters

* [tests] Changed incorrect '.' operators to ':' in two tests

* [tests] Updated STACKALLOC test to use STACKALLOC as an identifier for a local

* [tests] Set compiler profile to debug tests

Co-authored-by: cpyrgas <chris@xsharp.eu>
@cpyrgas
Copy link
Author

cpyrgas commented Jan 18, 2023

Confirmed fixed

@cpyrgas cpyrgas closed this as completed Jan 18, 2023
@cpyrgas cpyrgas moved this from Needs testing to Done in Build 2.15 - fixes in X# 2 Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants