例如,下面的示例
async function a() { await null; }
在VS代码中有一个关于等待的小警告
'await' has no effect on the type of this expression. ts(80007)
如何使警告行为类似于VS代码和tsc中错误(更明显,编译失败)?
在我工作的公司,我们使用类型注释来定义函数的预期返回类型。大多数开发人员都在使用PyCharm,但我更喜欢使用VS代码。
VS代码IDE中的以下一行:
def example() -> [str]:
引发Pylance警告:
List expression not allowed in type annotation
Use List[T] to indicate a list type or Union[T1, T2] to indicate a union typePylance
想让我用:
def example() -> List[str]
尽管修复这一问题需要我检查整
下面的VS2008代码给出了一个“变量已经定义”的警告:
if (someVar) {
var a = 1;
}
else {
var a = 2;
}
警告出现在第二个var a = ...上。为了消除这个警告,我已经这样做了:
var a;
if (someVar) {
a = 1;
}
else {
a = 2;
}
但这是正确的做法吗?
谢谢,
AJ
我正在构建一个64位的C++代码VS 2015。
DWORD testVar;
testVar= strLen((LPCSTR)src);
// where src is a CString.
看到警告- C4267‘参数’:从'size_t‘到'DWORD’的转换,可能会丢失数据。
任何建议都会有帮助。
在编译自定义Linux内核时,我收到了一些警告。我已经将我的代码(用于调试)缩减为:
int sw_totcp(struct ip_vs_service *svc)
{
return(1);
}
EXPORT_SYMBOL(sw_totcp);
int (*sw_totcpcall)(struct ip_vs_service *) = &sw_totcp;
EXPORT_SYMBOL(sw_totcpcall);
并且仍然得到这些警告(对于函数和函数指针):
warning: data definition has no type or storage class [
给定以下示例代码:
int main()
{
int i;
auto f = [=]()mutable->int*
{
return &i;
};
return 0;
}
g++ v.4.8.1警告"address of local variable 'i‘returned".Clang v.3.2 (MacOS's Clang)警告“与本地变量’i‘相关的堆栈内存地址returned".Neither VS2012或VS2013 RC警告任何内容。
我对lambdas的理解
考虑一下VS2015中的代码
int a,b;
[]
{
int a; // C4456: declaration of 'a' hides previous local declaration
};
为什么a在lambda发出这样的警告?它在VS2013中编译得很好。
编辑:令人感兴趣的是,(并且错误地),下面的不是VS2013中的错误:
[a]
{
int a; // No error, even if `a` is captured.
a++;
};
当我尝试将myCurrentTry初始化为1,将myMaxTries初始化为5时,我遇到了一个警告,错误是:
非静态数据成员的类内初始化是C++11扩展-Wc++11-扩展。
实现这一目标的代码是:
class starUFO{
public:
void Reset();
int getMaxTries();
int getCurrentTry();
bool isGameWon();
bool checkGuessValidity(string);
private:
int myCurrentTry = 1;
int myMax
static void Main(string[] args)
{
var vs = new List<Person> { new Person(1) };
vs[0].IncrementAge();
Console.WriteLine(vs[0].Age); // output: 1
}
struct Person
{
public int Age { get; set; }
public Person(int age) : this()
{
Age = age;
}
public int IncrementA
在我的python代码中,我看到下面的警告到处都是;
Missing function or method docstringpylint(missing-function-docstring)
如何删除此警告?
我使用VS代码v1.64.0,Microsoft Python扩展为Visual代码v2022.0.1786462952。
我的同事都是经验丰富的C++黑客,他们转向.Net。他们无意中犯的错误之一是编写这样的代码:
catch(ArgumentExcepttion ae)
{
// Code here logs the exception message
// And this is supposed to re-throw the exeception
throw ae; // as opposed to throw;
// But, as we all know, doing this creates a new exception with a shorter stack t