Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
84685f57
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84685f57
编写于
12月 10, 2014
作者:
N
nmgafter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1090472-Ensure retargeted error symbols cause use-site errors
Also includes VB implementation (changeset 1383936)
上级
75c73cc1
变更
13
展开全部
显示空白变更内容
内联
并排
Showing
13 changed file
with
390 addition
and
68 deletion
+390
-68
Src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
Src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+9
-0
Src/Compilers/CSharp/Portable/CSharpResources.resx
Src/Compilers/CSharp/Portable/CSharpResources.resx
+3
-0
Src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+1
-0
Src/Compilers/CSharp/Portable/Symbols/ExtendedErrorTypeSymbol.cs
...pilers/CSharp/Portable/Symbols/ExtendedErrorTypeSymbol.cs
+18
-0
Src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
...rtable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
+14
-2
Src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
Src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
+7
-3
Src/Compilers/CSharp/Test/Symbol/BadSymbolReference.cs
Src/Compilers/CSharp/Test/Symbol/BadSymbolReference.cs
+197
-45
Src/Compilers/VisualBasic/Portable/Errors/Errors.vb
Src/Compilers/VisualBasic/Portable/Errors/Errors.vb
+1
-0
Src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.vb
...rtable/Symbols/Retargeting/RetargetingSymbolTranslator.vb
+8
-6
Src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
Src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
+9
-0
Src/Compilers/VisualBasic/Portable/VBResources.resx
Src/Compilers/VisualBasic/Portable/VBResources.resx
+3
-0
Src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
Src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
+3
-1
Src/Compilers/VisualBasic/Test/Semantic/Binding/BadSymbolReference.vb
...s/VisualBasic/Test/Semantic/Binding/BadSymbolReference.vb
+117
-11
未找到文件。
Src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
浏览文件 @
84685f57
...
...
@@ -3544,6 +3544,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to There is an error in a referenced assembly '{0}'..
/// </summary>
internal
static
string
ERR_ErrorInReferencedAssembly
{
get
{
return
ResourceManager
.
GetString
(
"ERR_ErrorInReferencedAssembly"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to A '{0}' character may only be escaped by doubling '{0}{0}' in an interpolated string..
/// </summary>
...
...
Src/Compilers/CSharp/Portable/CSharpResources.resx
浏览文件 @
84685f57
...
...
@@ -4014,4 +4014,7 @@
<data
name=
"ERR_EmptyFormatSpecifier"
xml:space=
"preserve"
>
<value>
Empty format specifier.
</value>
</data>
<data
name=
"ERR_ErrorInReferencedAssembly"
xml:space=
"preserve"
>
<value>
There is an error in a referenced assembly '{0}'.
</value>
</data>
</root>
Src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
浏览文件 @
84685f57
...
...
@@ -1301,5 +1301,6 @@ internal enum ErrorCode
ERR_EscapedCurly
=
8087
,
ERR_TrailingWhitespaceInFormatSpecifier
=
8088
,
ERR_EmptyFormatSpecifier
=
8089
,
ERR_ErrorInReferencedAssembly
=
8090
,
}
}
Src/Compilers/CSharp/Portable/Symbols/ExtendedErrorTypeSymbol.cs
浏览文件 @
84685f57
...
...
@@ -50,6 +50,18 @@ internal ExtendedErrorTypeSymbol(NamespaceOrTypeSymbol containingSymbol, string
this
.
resultKind
=
LookupResultKind
.
Empty
;
}
private
ExtendedErrorTypeSymbol
(
NamespaceOrTypeSymbol
containingSymbol
,
string
name
,
int
arity
,
DiagnosticInfo
errorInfo
,
bool
unreported
,
bool
variableUsedBeforeDeclaration
,
ImmutableArray
<
Symbol
>
candidateSymbols
,
LookupResultKind
resultKind
)
{
this
.
name
=
name
;
this
.
errorInfo
=
errorInfo
;
this
.
containingSymbol
=
containingSymbol
;
this
.
arity
=
arity
;
this
.
unreported
=
unreported
;
this
.
VariableUsedBeforeDeclaration
=
variableUsedBeforeDeclaration
;
this
.
candidateSymbols
=
candidateSymbols
;
this
.
resultKind
=
resultKind
;
}
internal
ExtendedErrorTypeSymbol
(
NamespaceOrTypeSymbol
guessSymbol
,
LookupResultKind
resultKind
,
DiagnosticInfo
errorInfo
,
bool
unreported
=
false
)
:
this
(
guessSymbol
.
ContainingNamespaceOrType
(),
guessSymbol
,
resultKind
,
errorInfo
,
unreported
)
{
...
...
@@ -68,6 +80,12 @@ internal ExtendedErrorTypeSymbol(NamespaceOrTypeSymbol containingSymbol, Immutab
Debug
.
Assert
(
candidateSymbols
.
IsEmpty
||
resultKind
!=
LookupResultKind
.
Viable
,
"Shouldn't use LookupResultKind.Viable with candidate symbols"
);
}
internal
ExtendedErrorTypeSymbol
AsUnreported
()
{
return
this
.
Unreported
?
this
:
new
ExtendedErrorTypeSymbol
(
containingSymbol
,
name
,
arity
,
errorInfo
,
true
,
VariableUsedBeforeDeclaration
,
candidateSymbols
,
resultKind
);
}
private
static
ImmutableArray
<
Symbol
>
UnwrapErrorCandidates
(
ImmutableArray
<
Symbol
>
candidateSymbols
)
{
var
candidate
=
candidateSymbols
.
IsEmpty
?
null
:
candidateSymbols
[
0
]
as
ErrorTypeSymbol
;
...
...
Src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
浏览文件 @
84685f57
...
...
@@ -699,10 +699,22 @@ public PointerTypeSymbol Retarget(PointerTypeSymbol type)
public
static
ErrorTypeSymbol
Retarget
(
ErrorTypeSymbol
type
)
{
// TODO: produce an error symbol that will trigger an error on use
// TODO: if it is a missing symbol error but no longer missing in the target assembly, then we can resolve it here.
var
useSiteDiagnostic
=
type
.
GetUseSiteDiagnostic
();
if
(
useSiteDiagnostic
!=
null
)
{
return
type
;
}
// A retargeted error symbol must trigger an error on use so that a dependent compilation won't
// improperly succeed. We therefore ensure we have a use-site diagnostic.
return
(
type
as
ExtendedErrorTypeSymbol
)?.
AsUnreported
()
??
// preserve diagnostic information if possible
new
ExtendedErrorTypeSymbol
(
type
,
type
.
ResultKind
,
type
.
ErrorInfo
??
new
CSDiagnosticInfo
(
ErrorCode
.
ERR_ErrorInReferencedAssembly
,
type
.
ContainingAssembly
?.
Identity
.
GetDisplayName
()
??
string
.
Empty
),
true
);
}
public
ImmutableArray
<
Symbol
>
Retarget
(
ImmutableArray
<
Symbol
>
arr
)
{
var
symbols
=
ArrayBuilder
<
Symbol
>.
GetInstance
(
arr
.
Length
);
...
...
Src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
浏览文件 @
84685f57
...
...
@@ -4881,7 +4881,11 @@ public void M1(ITest34 y)
DiagnosticDescription
[]
expected
=
{
// error CS0246: The type or namespace name 'ITest33' could not be found (are you missing a using directive or an assembly reference?)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
).
WithArguments
(
"ITest33"
)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
).
WithArguments
(
"ITest33"
).
WithLocation
(
1
,
1
),
// error CS0246: The type or namespace name 'ITest33' could not be found (are you missing a using directive or an assembly reference?)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
).
WithArguments
(
"ITest33"
).
WithLocation
(
1
,
1
),
// error CS0246: The type or namespace name 'ITest33' could not be found (are you missing a using directive or an assembly reference?)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
).
WithArguments
(
"ITest33"
).
WithLocation
(
1
,
1
)
};
var
compilation1
=
CreateCompilationWithMscorlib
(
consumer
,
options
:
TestOptions
.
ReleaseExe
,
...
...
@@ -4933,7 +4937,7 @@ public void M1(ITest34 y)
{
// (10,9): error CS0246: The type or namespace name 'ITest33' could not be found (are you missing a using directive or an assembly reference?)
// y.M2(null);
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"y.M2
(null)"
).
WithArguments
(
"ITest33"
)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"y.M2
"
).
WithArguments
(
"ITest33"
).
WithLocation
(
10
,
9
)
};
VerifyEmitDiagnostics
(
compilation1
,
true
,
expected
);
...
...
Src/Compilers/CSharp/Test/Symbol/BadSymbolReference.cs
浏览文件 @
84685f57
此差异已折叠。
点击以展开。
Src/Compilers/VisualBasic/Portable/Errors/Errors.vb
浏览文件 @
84685f57
...
...
@@ -1672,6 +1672,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_ExpressionDoesntHaveName
=
37244
ERR_InvalidNameOfSubExpression
=
37245
ERR_MethodTypeArgsUnexpected
=
37246
ERR_InReferencedAssembly
=
37247
ERR_LastPlusOne
...
...
Src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.vb
浏览文件 @
84685f57
...
...
@@ -771,15 +771,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting
End
Function
Public
Function
Retarget
(
type
As
ErrorTypeSymbol
)
As
ErrorTypeSymbol
Dim
missing
As
MissingMetadataTypeSymbol
=
TryCast
(
type
,
MissingMetadataTypeSymbol
)
If
missing
IsNot
Nothing
Then
' TODO: if it is no longer missing in the target assembly, then we can resolve it here.
Return
missing
End
If
'TODO: produce an error symbol that will trigger an error on use
' A retargeted error symbol must trigger an error on use so that a dependent compilation won't
' improperly succeed. We therefore ensure we have a use-site diagnostic.
Dim
useSiteDiagnostic
=
type
.
GetUseSiteErrorInfo
If
useSiteDiagnostic
IsNot
Nothing
Then
Return
type
End
If
Dim
errorInfo
=
If
(
type
.
ErrorInfo
,
ErrorFactory
.
ErrorInfo
(
ERRID
.
ERR_InReferencedAssembly
,
If
(
type
.
ContainingAssembly
?
.
Identity
.
GetDisplayName
,
""
)))
Return
New
ExtendedErrorTypeSymbol
(
errorInfo
,
type
.
Name
,
type
.
Arity
,
type
.
CandidateSymbols
,
type
.
ResultKind
,
True
)
End
Function
Public
Function
Retarget
(
sequence
As
IEnumerable
(
Of
NamedTypeSymbol
))
As
IEnumerable
(
Of
NamedTypeSymbol
)
...
...
Src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
浏览文件 @
84685f57
...
...
@@ -5432,6 +5432,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to There is an error in a referenced assembly '{0}'..
'''</summary>
Friend ReadOnly Property ERR_InReferencedAssembly() As String
Get
Return ResourceManager.GetString("ERR_InReferencedAssembly", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to An expression is too long or complex to compile.
'''</summary>
...
...
Src/Compilers/VisualBasic/Portable/VBResources.resx
浏览文件 @
84685f57
...
...
@@ -4717,4 +4717,7 @@
<data
name=
"ERR_InvalidAssemblyCulture"
xml:space=
"preserve"
>
<value>
Assembly culture strings may not contain embedded NUL characters.
</value>
</data>
<data
name=
"ERR_InReferencedAssembly"
xml:space=
"preserve"
>
<value>
There is an error in a referenced assembly '{0}'.
</value>
</data>
</root>
Src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
浏览文件 @
84685f57
...
...
@@ -3894,7 +3894,9 @@ End Class
]]
></
file
>
</
compilation
>
Dim
errors
=
<
errors
>
BC36970
:
Failed
to
emit
module
'Consumer.dll'.
BC30002
:
Type
'I1' is not defined.
o
.
M2
(
Nothing
)
~~~~~~~~~~~~~
</
errors
>
Dim
piaCompilation2
=
CreateCompilationWithMscorlib
(
pia2
)
'CompileAndVerify(piaCompilation2, emitOptions:=EmitOptions.RefEmitBug)
...
...
Src/Compilers/VisualBasic/Test/Semantic/Binding/BadSymbolReference.vb
浏览文件 @
84685f57
...
...
@@ -319,26 +319,54 @@ BC30652: Reference required to assembly 'CL2, Version=0.0.0.0, Culture=neutral,
Dim
errors2
=
<
errors
>
BC30002
:
Type
'CL2_C1' is not defined.
CL3_C1
.
Test1
()
~~~~~~~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Global
.
CL3_C1
.
Test1
()
~~~~~~~~~~~~~~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Dim
z
As
Object
=
y
.
x
~~~
BC30002
:
Type
'CL2_C1' is not defined.
Inherits
CL3_C1
~~~~~~
BC30258
:
Classes
can
inherit
only
from
other
classes
.
Inherits
CL3_S1
~~~~~~
BC30002
:
Type
'CL2_I1' is not defined.
Inherits
CL3_I1
,
I1
(
Of
CL3_I1
)
~~~~~~
BC30002
:
Type
'CL2_I1' is not defined.
Implements
CL3_I1
,
I1
(
Of
CL3_I1
)
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
CL3_C2
.
Test1
()
~~~~~~~~~~~~~~
BC30469
:
Reference
to
a
non
-
shared
member
requires
an
object
reference
.
CL3_C2
.
Test1
(
1
)
~~~~~~~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
CL3_C2
.
Test3
()
~~~~~~~~~~~~~~
BC30516
:
Overload
resolution
failed
because
no
accessible
'Test4' accepts this number of arguments.
CL3_C2
.
Test4
()
~~~~~
BC30521
:
Overload
resolution
failed
because
no
accessible
'Test4' is most specific for these arguments:
'Public Shared Sub Test4(x As CL3_C1)': Not most specific.
'Public Shared Sub Test4(x As CL3_C3)': Not most specific.
BC30002
:
Type
'CL2_C1' is not defined.
CL3_C2
.
Test4
(
nothing
)
~~~~~
BC
42025
:
Access
of
shared
member
,
constant
member
,
enum
member
or
nested
type
through
an
instance
;
qualifying
expression
will
not
be
evaluat
ed
.
~~~~~~~~~~~~~~~~
~~~~~
BC
30002
:
Type
'CL2_C1' is not defin
ed.
y
.
Test1
()
~~~~~~~
BC3
1143
:
Method
'Public Sub Test2(x As Integer)' does not have a signature compatible with delegate 'Delegate Sub CL3_D1(x As CL2_C1)'
.
~~~~~~~
~~
BC3
0002
:
Type
'CL2_C1' is not defined
.
Dim
d1
As
CL3_D1
=
AddressOf
y
.
Test2
~~~~~~~
~~~~~~~~~~~~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
y
.
w
(
Nothing
)
~~~
BC30002
:
Type
'CL2_C1' is not defined.
Dim
u
As
CL3_D1
=
Sub
(
uuu
)
System
.
Console
.
WriteLine
()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</
errors
>
CompilationUtils
.
AssertTheseDiagnostics
(
compilation4
,
errors2
)
...
...
@@ -385,8 +413,87 @@ BC30002: Type 'CL2_I1' is not defined.
Dim
compilation5
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntimeAndReferences
(
source
,
{
New
VisualBasicCompilationReference
(
cl3BadCompilation2
)},
options
:
=
TestOptions
.
ReleaseExe
)
CompilationUtils
.
AssertTheseDiagnostics
(
compilation5
,
errors2
)
Dim
errors5
=
<
errors
>
BC30258
:
Classes
can
inherit
only
from
other
classes
.
Inherits
CL3_S1
~~~~~~
BC30469
:
Reference
to
a
non
-
shared
member
requires
an
object
reference
.
CL3_C2
.
Test1
(
1
)
~~~~~~~~~~~~
BC30516
:
Overload
resolution
failed
because
no
accessible
'Test4' accepts this number of arguments.
CL3_C2
.
Test4
()
~~~~~
BC30521
:
Overload
resolution
failed
because
no
accessible
'Test4' is most specific for these arguments:
'Public Shared Sub Test4(x As CL3_C1)': Not most specific.
'Public Shared Sub Test4(x As CL3_C3)': Not most specific.
CL3_C2
.
Test4
(
nothing
)
~~~~~
BC42025
:
Access
of
shared
member
,
constant
member
,
enum
member
or
nested
type
through
an
instance
;
qualifying
expression
will
not
be
evaluated
.
y
.
Test1
()
~~~~~~~
BC31143
:
Method
'Public Sub Test2(x As Integer)' does not have a signature compatible with delegate 'Delegate Sub CL3_D1(x As CL2_C1)'.
Dim
d1
As
CL3_D1
=
AddressOf
y
.
Test2
~~~~~~~
</
errors
>
CompilationUtils
.
AssertTheseDiagnostics
(
compilation5
,
errors5
)
Dim
errors6
=
<
errors
>
BC30258
:
Classes
can
inherit
only
from
other
classes
.
Inherits
CL3_S1
~~~~~~
BC30469
:
Reference
to
a
non
-
shared
member
requires
an
object
reference
.
CL3_C2
.
Test1
(
1
)
~~~~~~~~~~~~
BC30516
:
Overload
resolution
failed
because
no
accessible
'Test4' accepts this number of arguments.
CL3_C2
.
Test4
()
~~~~~
BC30521
:
Overload
resolution
failed
because
no
accessible
'Test4' is most specific for these arguments:
'Public Shared Sub Test4(x As CL3_C1)': Not most specific.
'Public Shared Sub Test4(x As CL3_C3)': Not most specific.
CL3_C2
.
Test4
(
nothing
)
~~~~~
BC42025
:
Access
of
shared
member
,
constant
member
,
enum
member
or
nested
type
through
an
instance
;
qualifying
expression
will
not
be
evaluated
.
y
.
Test1
()
~~~~~~~
BC31143
:
Method
'Public Sub Test2(x As Integer)' does not have a signature compatible with delegate 'Delegate Sub CL3_D1(x As CL2_C1)'.
Dim
d1
As
CL3_D1
=
AddressOf
y
.
Test2
~~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Inherits
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
Shared
Function
Test2
()
As
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
Function
Test3
()
As
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
Shared
Function
Test1
()
As
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
x
As
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
Shared
Function
Test3
()
As
CL2_C1
~~~~~~
BC30002
:
Type
'CL2_I1' is not defined.
Implements
CL2_I1
,
CL2_I2
~~~~~~
BC30002
:
Type
'CL2_I2' is not defined.
Implements
CL2_I1
,
CL2_I2
~~~~~~
BC30002
:
Type
'CL2_C1' is not defined.
Public
Delegate
Sub
CL3_D1
(
x
As
CL2_C1
)
~~~~~~
BC30002
:
Type
'CL2_I1' is not defined.
Implements
CL2_I1
~~~~~~
BC30002
:
Type
'CL2_I1' is not defined.
Inherits
CL2_I1
~~~~~~
</
errors
>
Dim
cl4Source
=
<
compilation
name
=
"cl4"
>
<
%
=
a_vb
%
>
...
...
@@ -395,8 +502,7 @@ BC30002: Type 'CL2_I1' is not defined.
Dim
compilation6
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
cl4Source
)
CompilationUtils
.
AssertTheseDiagnostics
(
compilation6
,
<
error
><
%
=
errors2
.
Value
.
TrimEnd
()
+
errors3
.
Value
%
></
error
>
)
CompilationUtils
.
AssertTheseDiagnostics
(
compilation6
,
errors6
)
CompilationUtils
.
AssertNoErrors
(
compilation1
)
End
Sub
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录