Bug 3575 - static member on Generic Type is not resolved correcly.
Summary: static member on Generic Type is not resolved correcly.
Status: RESOLVED UPSTREAM
Alias: None
Product: Compilers
Classification: Mono
Component: VisualBasic ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-02-22 01:49 UTC by himajin100000
Modified: 2018-05-22 12:06 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description himajin100000 2012-02-22 01:49:48 UTC
STEPS TO REPRODUCE:

	1. Try to compile the following code.
	
	Option Explicit On
	Option Strict On
	Option Compare Binary
	
	REM http://ideone.com/hIFzL
	 
	Public Class Test1(Of T)
	        Public Function Test11(t1 As T) As T
	                Return t1
	        End Function
	 
	        Public Shared Function Test12(t1 As T) As T
	                Return t1
	        End Function
	End Class
	 
	Public Class Test2
	        Public Shared Function Test21(Of T)(t1 As T) As T
	                Return t1
	        End Function
	End Class
	 
	Public Class Main
	        Public Shared Sub Main()
	                
	                REM OK
	                Dim a As Integer = (New Test1(Of Integer)).Test11(5) 
	 
	                REM OK
	                Dim b As Integer = Test2.Test21(Of Integer) (5)
	 
	                REM NG
	                Dim c As Integer = Test1(Of Integer).Test12(5) 
	        End Sub
	End Class

EXPECTED RESULT:

	No Error.
	
ACTUAL RESULT:
	
	/home/d8NCgg/prog.vb (34,27) : Error VBNC30451: Could not resolve the name 'Test1'
There were 1 errors and 0 warnings.

ADDITIONAL NOTE:
	
	THIS NOTE MAY BE COMPLETELY WRONG.

	I'm not sure about my understanding, but from experiments I did via building and modifying the code,
	
	I think Parser seems correctly recognizing the type name with type arguments, and treats them as a SimpleNameExpression
	I think	the SimpleNameExpression should be classified as TypeClassification when the program executes ResolveExpressionInternal.
	
	However, while local variable Name was "Test1", 
	the real key Dictionary returned from Compiler.TypeManager.GetTypesByNamespace(currentNS) actually contained was "Test1`1".
	https://github.com/mono/mono-basic/blob/master/vbnc/vbnc/source/Expressions/SimpleNameExpression.vb#L174	
	https://github.com/mono/mono-basic/blob/master/vbnc/vbnc/source/Expressions/SimpleNameExpression.vb#L452

	Therefore the dictionary returned Nothing, reaching the code reporting the specified error.
	
	https://github.com/mono/mono-basic/blob/master/vbnc/vbnc/source/Expressions/SimpleNameExpression.vb#L559
	
	As a workaround, I modified the code to
	
		If Name = "Test1" Then
			Name = "Test1`1"
			foundType = Compiler.TypeManager.GetTypesByNamespace(currentNS).Item(Name) 
		Else
		
			foundType = Compiler.TypeManager.GetTypesByNamespace(currentNS).Item(Name)
		End If
	
	compiled the source and ran the program. 
	It seems successfully recognizing the type, however, 
	the program still was thinking Test12(t1 As T) As T,  not Test12(t1 As Integer) As Integer, causing the compiler to report

		error VBNC30518: Overload resolution failed because no accessible 'Test12' can be called with these arguments:
    'Public Function Test12(t1 As T) As T': Value of type 'Integer' cannot be converted to 'T'.
	
	then I rewrote
	
	        Dim foundType As Mono.Cecil.TypeReference
		If Name = "Test1" Then
			Dim foundType2 As Mono.Cecil.GenericInstanceType
			Name = "Test1`1"
			foundType = Compiler.TypeManager.GetTypesByNamespace(currentNS).Item(Name) 
			foundType2 = new GenericInstanceType(foundType)
			foundType2.GenericArguments.AddRange(m_TypeArgumentList.ArgumentCollection)
			foundType = foundType2
		Else                            
			foundType = Compiler.TypeManager.GetTypesByNamespace(currentNS).Item(Name)            
		End If
	
	and got another error caused by TypeClassification constructor. I was not sure whether I should add route to accept GenericInstanceType,
	,gave up the investigation, decided to report this bug.   
	
	https://github.com/mono/mono-basic/blob/master/vbnc/vbnc/source/Expressions/Classifications/TypeClassification.vb#L128
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-02-22 06:45:40 UTC
There is an interesting workaround:

Dim c As Integer = (New Test1(Of Integer)).Test12(5)

And the Test1(Of Integer) object won't even be created, since Test12 is a static method.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2018-05-22 12:06:07 UTC
Moved to: https://github.com/mono/mono-basic/issues/26