@lcap/nasl-language-server-core 4.4.1-rc.1 → 4.4.1-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/checker.d.ts.map +1 -1
- package/out/checker.js +5 -104
- package/out/checker.js.map +1 -1
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +27 -11
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +1 -0
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +2 -0
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +20 -0
- package/out/typer/unifier.js.map +1 -1
- package/package.json +5 -5
package/out/checker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAC4C,QAAQ,EAC5B,IAAI,EAQ+E,GAAG,EAMxH,QAAQ,EAGT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAGpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAYpE,oBAAY,QAAQ;IAClB,IAAI,YAAY;IAChB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAEnE,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAOF,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAEpE,M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AC,CAAC;IACrC,mBAAmB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC1C;AAMD,eAAO,MAAM,6BAA6B,aAC9B,UAAU,+DAGnB,MAAM,gBAAgB,CAyCxB,CAAC;AAMF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/out/checker.js
CHANGED
|
@@ -257,7 +257,7 @@ function createErrorDiagnoser(context) {
|
|
|
257
257
|
let env = context.env;
|
|
258
258
|
let isDebug = context.debug;
|
|
259
259
|
// 严格模式
|
|
260
|
-
let
|
|
260
|
+
let isAIStrictMode = context.isAIStrictMode;
|
|
261
261
|
// 引用管理器
|
|
262
262
|
let referenceManager = env.refMgr;
|
|
263
263
|
// 检查共享数据是否有更新
|
|
@@ -899,7 +899,7 @@ function createErrorDiagnoser(context) {
|
|
|
899
899
|
continue;
|
|
900
900
|
}
|
|
901
901
|
// 严格模式非必填也需要有Argument占位
|
|
902
|
-
if (
|
|
902
|
+
if (isAIStrictMode || !isNonRequiredParam(param)) {
|
|
903
903
|
minArgsCount++; // 如果参数有默认值,则跳过
|
|
904
904
|
}
|
|
905
905
|
}
|
|
@@ -1018,7 +1018,7 @@ function createErrorDiagnoser(context) {
|
|
|
1018
1018
|
}
|
|
1019
1019
|
else if (argsLen < minArgsCount) {
|
|
1020
1020
|
let msg = `传入参数的个数 ${argsLen} 与 ${getExpressionNodeName(node.concept)} 定义的参数个数 ${paramsLen} 不符。`;
|
|
1021
|
-
if (
|
|
1021
|
+
if (isAIStrictMode) {
|
|
1022
1022
|
msg += `可选参数和默认值参数必须用 undefined 占位`;
|
|
1023
1023
|
}
|
|
1024
1024
|
error(node, msg);
|
|
@@ -1777,7 +1777,7 @@ function createErrorDiagnoser(context) {
|
|
|
1777
1777
|
const decimalPlaces = value?.split('.')[1]?.length || 0;
|
|
1778
1778
|
if (decimalPlaces > +scale) {
|
|
1779
1779
|
error(node, `实体字段${node.name}默认值的小数位数不能大于设置的小数位数${scale},否则将会按照小数位数自动截断`, {
|
|
1780
|
-
severity:
|
|
1780
|
+
severity: isAIStrictMode ? Severity.ERROR : Severity.WARN,
|
|
1781
1781
|
});
|
|
1782
1782
|
}
|
|
1783
1783
|
}
|
|
@@ -4313,97 +4313,6 @@ function createErrorDiagnoser(context) {
|
|
|
4313
4313
|
}
|
|
4314
4314
|
return env.getType(node);
|
|
4315
4315
|
}
|
|
4316
|
-
/**
|
|
4317
|
-
* 递归检查赋值类型不兼容问题
|
|
4318
|
-
* 检查左侧类型(Decimal/Long)是否与右侧联合类型(Union<Decimal, Long>)不兼容
|
|
4319
|
-
* @param leftType 左侧类型
|
|
4320
|
-
* @param rightType 右侧类型
|
|
4321
|
-
* @param context 上下文信息,用于生成错误消息
|
|
4322
|
-
* @param allowImplicitConversion 是否允许隐式类型转换(仅对直接的基础类型赋值允许,复杂类型内部不允许)
|
|
4323
|
-
* @returns 所有类型不兼容的错误信息数组
|
|
4324
|
-
*/
|
|
4325
|
-
function checkAssignmentTypeIncompatibility(leftType, rightType, context = {}, allowImplicitConversion = true) {
|
|
4326
|
-
if (!leftType || !rightType)
|
|
4327
|
-
return [];
|
|
4328
|
-
const errors = [];
|
|
4329
|
-
// 先检查 Decimal/Long vs Union<Decimal, Long> 的情况(需要先于其他检查)
|
|
4330
|
-
// 这种情况应该报错,即使允许隐式转换
|
|
4331
|
-
if (allowImplicitConversion) {
|
|
4332
|
-
const isLeftPrimitive = leftType.typeKind === 'primitive';
|
|
4333
|
-
const isLeftDecimalOrLong = isLeftPrimitive && (leftType.typeName === 'Decimal' || leftType.typeName === 'Long');
|
|
4334
|
-
if (isLeftDecimalOrLong && (0, type_predicate_1.isDecimalUnionLongTy)(rightType)) {
|
|
4335
|
-
const prefix = context.prefix || '赋值';
|
|
4336
|
-
const fieldInfo = context.fieldName ? `字段 ${context.fieldName} ` : '';
|
|
4337
|
-
errors.push(`${prefix}:${fieldInfo}类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
|
|
4338
|
-
return errors; // 找到基本类型错误后直接返回,不再检查嵌套
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
// 检查基础类型是否严格相等(不允许隐式转换)
|
|
4342
|
-
const isLeftPrimitive = leftType.typeKind === 'primitive';
|
|
4343
|
-
const isRightPrimitive = rightType.typeKind === 'primitive';
|
|
4344
|
-
if (isLeftPrimitive && isRightPrimitive) {
|
|
4345
|
-
// 如果不允许隐式转换,则要求类型完全相等
|
|
4346
|
-
if (!allowImplicitConversion) {
|
|
4347
|
-
if (leftType.typeName !== rightType.typeName || leftType.typeNamespace !== rightType.typeNamespace) {
|
|
4348
|
-
const prefix = context.prefix || '赋值';
|
|
4349
|
-
const fieldInfo = context.fieldName ? `字段 ${context.fieldName} ` : '';
|
|
4350
|
-
errors.push(`${prefix}:${fieldInfo}类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
|
|
4351
|
-
return errors;
|
|
4352
|
-
}
|
|
4353
|
-
// 类型完全相等,没有错误,继续检查其他情况
|
|
4354
|
-
}
|
|
4355
|
-
else {
|
|
4356
|
-
// 允许隐式转换的情况下,检查是否通过 isSubTy 检查(允许隐式转换)
|
|
4357
|
-
if ((0, type_predicate_1.isSubTy)(env, rightType, leftType)) {
|
|
4358
|
-
// 类型兼容(允许隐式转换),没有错误,继续检查其他情况
|
|
4359
|
-
}
|
|
4360
|
-
// 如果 isSubTy 返回 false,继续检查其他不兼容的情况
|
|
4361
|
-
}
|
|
4362
|
-
}
|
|
4363
|
-
// 2. 检查 List 类型(包括嵌套):List<T> vs List<Union<...>>
|
|
4364
|
-
if (leftType.typeKind === 'generic' &&
|
|
4365
|
-
leftType.typeName === 'List' &&
|
|
4366
|
-
rightType.typeKind === 'generic' &&
|
|
4367
|
-
rightType.typeName === 'List' &&
|
|
4368
|
-
leftType.typeArguments?.[0] &&
|
|
4369
|
-
rightType.typeArguments?.[0]) {
|
|
4370
|
-
// 递归检查 List 的元素类型,嵌套类型内部不允许隐式转换
|
|
4371
|
-
return checkAssignmentTypeIncompatibility(leftType.typeArguments[0], rightType.typeArguments[0], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4372
|
-
);
|
|
4373
|
-
}
|
|
4374
|
-
// 3. 检查 Map 类型(包括嵌套):Map<K, V> vs Map<K, Union<...>>
|
|
4375
|
-
if (leftType.typeKind === 'generic' &&
|
|
4376
|
-
leftType.typeName === 'Map' &&
|
|
4377
|
-
rightType.typeKind === 'generic' &&
|
|
4378
|
-
rightType.typeName === 'Map' &&
|
|
4379
|
-
leftType.typeArguments?.length === 2 &&
|
|
4380
|
-
rightType.typeArguments?.length === 2) {
|
|
4381
|
-
// 递归检查 Map 的值类型(第二个类型参数),嵌套类型内部不允许隐式转换
|
|
4382
|
-
const valueTypeErrors = checkAssignmentTypeIncompatibility(leftType.typeArguments[1], rightType.typeArguments[1], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4383
|
-
);
|
|
4384
|
-
errors.push(...valueTypeErrors);
|
|
4385
|
-
// 也检查键类型(第一个类型参数),嵌套类型内部不允许隐式转换
|
|
4386
|
-
const keyTypeErrors = checkAssignmentTypeIncompatibility(leftType.typeArguments[0], rightType.typeArguments[0], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4387
|
-
);
|
|
4388
|
-
errors.push(...keyTypeErrors);
|
|
4389
|
-
return errors;
|
|
4390
|
-
}
|
|
4391
|
-
// 4. 检查匿名结构体:递归检查每个字段,收集所有字段的错误
|
|
4392
|
-
if ((0, type_predicate_1.isAnonymousTy)(leftType) && (0, type_predicate_1.isAnonymousTy)(rightType)) {
|
|
4393
|
-
const leftProps = leftType.properties ?? [];
|
|
4394
|
-
const rightProps = rightType.properties ?? [];
|
|
4395
|
-
for (const leftProp of leftProps) {
|
|
4396
|
-
const rightProp = rightProps.find(p => p.name === leftProp.name);
|
|
4397
|
-
if (rightProp && leftProp.typeAnnotation && rightProp.typeAnnotation) {
|
|
4398
|
-
// 匿名结构体的字段类型检查不允许隐式转换
|
|
4399
|
-
const fieldErrors = checkAssignmentTypeIncompatibility(leftProp.typeAnnotation, rightProp.typeAnnotation, { prefix: context.prefix || '赋值', fieldName: leftProp.name }, false // 复杂类型内部不允许隐式转换
|
|
4400
|
-
);
|
|
4401
|
-
errors.push(...fieldErrors); // 收集所有字段的错误,不提前返回
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
}
|
|
4405
|
-
return errors;
|
|
4406
|
-
}
|
|
4407
4316
|
/**
|
|
4408
4317
|
* 检查 赋值语句
|
|
4409
4318
|
* @param node
|
|
@@ -4415,14 +4324,6 @@ function createErrorDiagnoser(context) {
|
|
|
4415
4324
|
if (ensureNodeKeyExists(node, 'right')) {
|
|
4416
4325
|
yield* checkNode(node.right);
|
|
4417
4326
|
}
|
|
4418
|
-
// 使用统一的类型兼容性检查
|
|
4419
|
-
const leftType = env.getType(node.left);
|
|
4420
|
-
const rightType = env.getType(node.right);
|
|
4421
|
-
const errorMessages = checkAssignmentTypeIncompatibility(leftType, rightType);
|
|
4422
|
-
// 报告所有错误
|
|
4423
|
-
errorMessages.forEach(errorMessage => {
|
|
4424
|
-
error(node, errorMessage);
|
|
4425
|
-
});
|
|
4426
4327
|
if (nasl_concepts_1.asserts.isMemberExpression(node.left)) {
|
|
4427
4328
|
reportCurrentItemModification(node.left, node);
|
|
4428
4329
|
}
|
|
@@ -4488,7 +4389,7 @@ function createErrorDiagnoser(context) {
|
|
|
4488
4389
|
error(args[i], '当前参数无效,不可用。');
|
|
4489
4390
|
}
|
|
4490
4391
|
}
|
|
4491
|
-
if (
|
|
4392
|
+
if (isAIStrictMode) {
|
|
4492
4393
|
yield* checkCallExpressionParameters(node, ref);
|
|
4493
4394
|
}
|
|
4494
4395
|
}
|