Skip to content

Commit c8a6afb

Browse files
committed
Fixes
1 parent 4747ec3 commit c8a6afb

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ final class Ast implements BuildMode
4242
private ?string $needsParent = null;
4343

4444
public function __construct(
45-
public readonly bool $allowBackrefs,
4645
public readonly bool $allowUnpacking,
4746
private array $outputSchema = []
4847
) {
@@ -159,9 +158,6 @@ public function getNeedsParent(): ?string
159158

160159
public function setNeedsParent(string $needsParent): void
161160
{
162-
if (!$this->allowBackrefs) {
163-
throw new \LogicException('Cannot set needsParent when backreferences are not allowed.');
164-
}
165161
if ($this->needsParent !== null && $this->needsParent !== $needsParent) {
166162
throw new \LogicException("Cannot change needsParent from {$this->needsParent} to {$needsParent} once it has been set.");
167163
}

tools/FileRefExtractor/Path.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public function __construct(
3232
/** @var list<list{0: string, 1: string, 2?: int-mask-of<self::FLAG_*>|TypedOp}> */
3333
public array $path,
34-
public ?bool $isFromParent = null,
34+
public bool $isFromParent = false,
3535
) {
3636
foreach ($path as $k => $elem) {
3737
if (\count($elem) !== 2 && \count($elem) !== 3) {
@@ -57,7 +57,6 @@ public function __construct(
5757

5858
public function normalize(array $stack, string $current, bool $ignoreFlag): ?self
5959
{
60-
Assert::null($this->isFromParent, 'Already normalized');
6160
$new = [];
6261
foreach ($this->path as $i => $part) {
6362
if ($ignoreFlag && \array_key_exists(2, $part) && \is_int($part[2]) && ($part[2] & self::FLAG_IF_ABSENT_ABORT)) {
@@ -72,17 +71,18 @@ public function normalize(array $stack, string $current, bool $ignoreFlag): ?sel
7271
}
7372
$new[$i] = $part;
7473
}
75-
if ($current === $this->path[0][0]) {
76-
return new self(
77-
[...$stack, ...$new],
78-
false,
79-
);
80-
}
81-
// From parent
82-
if ($stack[0][0] === $this->path[0][0]) {
83-
return new static($new, true);
74+
if ($this->isFromParent) {
75+
// From parent
76+
if ($stack[0][0] === $this->path[0][0]) {
77+
return new static($new, true);
78+
}
79+
return null;
8480
}
85-
return null;
81+
Assert::eq($this->path[0][0], $current);
82+
return new self(
83+
[...$stack, ...$new],
84+
false,
85+
);
8686
}
8787

8888
public function buildPath(TLContext $tl, string $extractor): array
@@ -166,7 +166,6 @@ public function buildPath(TLContext $tl, string $extractor): array
166166
'type' => $type,
167167
];
168168
}
169-
Assert::notNull($this->isFromParent, 'Not normalized');
170169
if ($this->isFromParent) {
171170
$tl->buildMode->setNeedsParent($this->path[0][0]);
172171
}

tools/FileRefExtractor/TLWrapper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
namespace danog\MadelineProto\FileRefExtractor;
2020

2121
use danog\MadelineProto\TL\TL;
22-
use danog\MadelineProto\TL\TLInterface;
2322
use Webmozart\Assert\Assert;
2423

2524
final class TLWrapper

tools/gen_filerefmap.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use danog\MadelineProto\FileRefExtractor\Ops\GetInputStickerSet;
1212
use danog\MadelineProto\FileRefExtractor\Ops\GetInputUserOp;
1313
use danog\MadelineProto\FileRefExtractor\Ops\GetMessageOp;
14-
use danog\MadelineProto\FileRefExtractor\Ops\GetStickerSetFromDocumentAttributesOp;
1514
use danog\MadelineProto\FileRefExtractor\Ops\Noop;
1615
use danog\MadelineProto\FileRefExtractor\Ops\PrimitiveLiteralOp;
1716
use danog\MadelineProto\FileRefExtractor\Ops\ThemeFormatOp;
@@ -59,7 +58,7 @@
5958
'stories.getStoriesByID',
6059
[
6160
'id' => new ArrayOp(new CopyOp([['storyItem', 'id']])),
62-
'peer' => new GetInputPeerOp(new Path([[$method, 'peer']])),
61+
'peer' => new GetInputPeerOp(new Path([[$method, 'peer']], true)),
6362
],
6463
'fileSourceStory'
6564
);
@@ -112,7 +111,7 @@
112111
'stories.getStoriesByID',
113112
[
114113
'id' => new ArrayOp(new CopyOp([['storyItem', 'id']])),
115-
'peer' => new GetInputPeerOp(new Path([['peerStories', 'peer']])),
114+
'peer' => new GetInputPeerOp(new Path([['peerStories', 'peer']], true)),
116115
],
117116
'fileSourceStory'
118117
);
@@ -163,7 +162,7 @@
163162
$locations['channelAdminLogEvent'][] = new CallOp(
164163
'channels.getAdminLog',
165164
[
166-
'channel' => new GetInputChannelOp(new Path([['channels.getAdminLog', 'channel']])),
165+
'channel' => new GetInputChannelOp(new Path([['channels.getAdminLog', 'channel']], true)),
167166
'max_id' => new CopyOp([['channelAdminLogEvent', 'id']]),
168167
'min_id' => new CopyOp([['channelAdminLogEvent', 'id']]),
169168
'limit' => new PrimitiveLiteralOp('int', 1),
@@ -248,7 +247,7 @@
248247
'payments.getStarsTransactionsByID',
249248
[
250249
'peer' => new CopyOp([[$method, 'peer']]),
251-
...($method === 'payments.getStarsSubscriptions' ? [] : ['ton' => new CopyOp([[$method, 'ton', Path::FLAG_PASSTHROUGH]])]),
250+
...($method === 'payments.getStarsSubscriptions' ? [] : ['ton' => new CopyOp(new Path([[$method, 'ton', Path::FLAG_PASSTHROUGH]], true))]),
252251
'id' => new ArrayOp(new ConstructorOp(
253252
'inputStarsTransaction',
254253
[
@@ -356,7 +355,7 @@
356355
$locations['photo'][] = new CallOp(
357356
'photos.getUserPhotos',
358357
[
359-
'user_id' => new CopyOp([['photos.getUserPhotos', 'user_id']]),
358+
'user_id' => new CopyOp(new Path([['photos.getUserPhotos', 'user_id']], true)),
360359
'offset' => new PrimitiveLiteralOp('int', -1),
361360
'max_id' => new CopyOp([['photo', 'id']]),
362361
'limit' => new PrimitiveLiteralOp('int', 1),
@@ -512,7 +511,7 @@
512511

513512
$validated = [];
514513

515-
$tmp = new Ast(allowBackrefs: true, allowUnpacking: true, outputSchema: $pre);
514+
$tmp = new Ast(allowUnpacking: true, outputSchema: $pre);
516515
foreach (['Document' => 'document', 'Photo' => 'photo'] as $type => $constructor) {
517516
$stack = [[$constructor, 'file_reference']];
518517
$stackTypes = [$type => 1];
@@ -600,7 +599,7 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
600599
throw new AssertionError("Leftover ops!");
601600
}
602601

603-
$output = new Ast(allowBackrefs: true, allowUnpacking: false, outputSchema: $pre);
602+
$output = new Ast(allowUnpacking: false, outputSchema: $pre);
604603
foreach ($locations as $constructor => $ops) {
605604
foreach ($ops as $idx => $op) {
606605
$op->build(new TLContext($TL, $output, $constructor, $TL->isConstructor($constructor)));

0 commit comments

Comments
 (0)