Skip to content

一些3.4.0新增功能的语法检查异常 #1260

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

Open
Whimsyduke opened this issue Jun 30, 2022 · 23 comments
Open

一些3.4.0新增功能的语法检查异常 #1260

Whimsyduke opened this issue Jun 30, 2022 · 23 comments
Labels
bug Something isn't working enhancement New feature or request feat/type check Related to the type checking feature Info Needed More information is required

Comments

@Whimsyduke
Copy link

image
image
单独写lua没能复现
另外有没有强制修改类型的配置方式,比如
`---@Class A
local a = {}
---@Class B:A

---@type string|number
local c = 1

---comment
---@return A
---@return string|number
local function func1()
return a, c
end

---comment
---@return B
---@return number
local function func2()
local ta, tb = func1()
return ta, tb
end`
在这种情况下我怎么去配置使ta、ta符合返回值类型?

@Whimsyduke
Copy link
Author

Whimsyduke commented Jun 30, 2022

感觉上可以加个忽略可控类型验证的配置,不然现有代码出现太多错误了,大部分都是没验证空

@sumneko
Copy link
Collaborator

sumneko commented Jun 30, 2022

可以使用 ---@cast var type--[[@as type]] 转换类型,我晚点写个文档。

@sumneko sumneko added bug Something isn't working enhancement New feature or request feat/type check Related to the type checking feature labels Jun 30, 2022
@Whimsyduke
Copy link
Author

Whimsyduke commented Jun 30, 2022

image
image
所有分支都return了

@sumneko
Copy link
Collaborator

sumneko commented Jun 30, 2022

image image 所有分支都return了

你再看看?

@Whimsyduke
Copy link
Author

呃,最后一个不是else,我的错

@septbr
Copy link

septbr commented Jul 1, 2022

---@type UnityEngine.Vector3
local x = Vector3.zero
x = x + x  已显式定义变量的类型为 `UnityEngine.Vector3` ,不能再将其类型转换为 `number`

算术运算都变成number了

另外number和integer不兼容,这个检查太头疼了

@sumneko
Copy link
Collaborator

sumneko commented Jul 1, 2022

另外number和integer不兼容,这个检查太头疼了

设置里有让 number 和 integer 兼容的选项

@sumneko
Copy link
Collaborator

sumneko commented Jul 1, 2022

算术运算都变成number了

3.5.0 会支持重载运算符,可以解决这个问题

@sumneko
Copy link
Collaborator

sumneko commented Jul 1, 2022

image
单独写lua没能复现

你在原来的代码上删除业务代码,只保留一个结构看看

sumneko added a commit that referenced this issue Jul 1, 2022
@sumneko sumneko added the Info Needed More information is required label Jul 1, 2022
@Whimsyduke
Copy link
Author

我家里没能复现,周一上班公司的提示也没了

@sumneko
Copy link
Collaborator

sumneko commented Jul 4, 2022

我家里没能复现,周一上班公司的提示也没了

我今天又大改了一下局部变量追踪,可能已经修复了,之后再观察一下。

@sniper00
Copy link

sniper00 commented Jul 5, 2022

诊断速度变慢,写代码时十几秒才能诊断完

@sumneko
Copy link
Collaborator

sumneko commented Jul 5, 2022

诊断速度变慢,写代码时十几秒才能诊断完

请开一个新的issue并提供日志与可复现此问题的演示工程

@sniper00
Copy link

sniper00 commented Jul 5, 2022

诊断速度变慢,写代码时十几秒才能诊断完

请开一个新的issue并提供日志与可复现此问题的演示工程

示例估计太好复现,我是拿我们的项目来说的,文件比较多 500多个

@sumneko
Copy link
Collaborator

sumneko commented Jul 5, 2022

500个应该是没问题的,我的工作项目有1500+个文件也无压力,应该是有什么隐藏的bug导致的,这个只有用示例调试才好查

@sniper00
Copy link

sniper00 commented Jul 5, 2022

500个应该是没问题的,我的工作项目有1500+个文件也无压力,应该是有什么隐藏的bug导致的,这个只有用示例调试才好查
这个版本我们项目有 800多个诊断问题 会不会和这个有关系,我们有1500多个类型注解

@sniper00
Copy link

sniper00 commented Jul 5, 2022

有没有方法实现可选返回值?

@sumneko
Copy link
Collaborator

sumneko commented Jul 5, 2022

有没有方法实现可选返回值?

---@return number?

@sniper00
Copy link

sniper00 commented Jul 5, 2022

有没有方法实现可选返回值?

---@return number?

这种怎么处理,手动写个 return nil?

---@return BattleRecordOne?
function BattleEnemy:GetBattleRecord()
    if self.battleRecord then
        return self.battleRecord.record
    end--这里提示要返回值
end

@sumneko
Copy link
Collaborator

sumneko commented Jul 5, 2022

---@return BattleRecordOne?
function BattleEnemy:GetBattleRecord()
    if self.battleRecord then
        return self.battleRecord.record
    end--这里提示要返回值
end

#1257

@sniper00
Copy link

sniper00 commented Jul 5, 2022

local tm = os.date("*t", os.time())
local t = os.time(tm) -- 不能将 `string|osdate` 赋给参数 `osdate?`。

@sumneko
Copy link
Collaborator

sumneko commented Jul 5, 2022

local tm = os.date("*t", os.time())
local t = os.time(tm) -- 不能将 `string|osdate` 赋给参数 `osdate?`。

开个单独的issue,以后版本改为分析参数来决定返回值

@sumneko
Copy link
Collaborator

sumneko commented Sep 19, 2022

Is there any other issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request feat/type check Related to the type checking feature Info Needed More information is required
Projects
None yet
Development

No branches or pull requests

4 participants